SAS proc ds2 YEAR function

I am getting an odd error code trying to get the DS2 stream up and running.

   proc ds2;
   thread work.th_ieb /overwrite=yes;
   dcl DOUBLE Beg_Jahr;
   METHOD RUN();
    set {select id, date
       from DATA
       };
    IF FIRST.id THEN DO;
    Beg_Jahr    = YEAR(DATE);
    OUTPUT;
    END;
 END;
endthread;
run;

      

Mistake:

ERROR: Compilation error.
ERROR: Illegal conversion for date or time type. Source line 34.

      

It works fine without YEAR function. Any ideas?

+3


source to share


2 answers


Here is the complete sample program I used to reproduce your problem and this version works on my site. One of the key changes is the "dt" format using 11.0 instead of date9 in the original sas data. I couldn't get it to work with date9 even though the SAS docs say it should.



data stuff;
  format dt 11.0 id 11.0;
    dt='01JAN2015'd;
    id = 1;
run;

proc ds2;
    thread work.th_ieb /overwrite=yes;
        dcl double Beg_Jahr;
        dcl date ds2_dt having format yymmdd10.;

        METHOD RUN();
          set {select id, dt
                 from stuff
                order by id
              };
          by id;

            ds2_dt = to_date(dt);
            put ds2_dt=;

            IF FIRST.id THEN DO;
                Beg_Jahr = year(dt);
                put beg_jahr=;
                OUTPUT;
            END;
        END;
    endthread;

    data;
        dcl thread th_ieb t_inst;

        method run();
          set from t_inst threads=2;
        end;
    enddata;
run;

      

+1


source


I freely admit that I don't fully understand all the intricacies of DS2, but this solution works for me.

Change the name of the variable you named date

to something else, as date

is a keyword in DS2. DS2 is much broader than basic SAS about these things. Here I will name the variable birthdt

for example only.



Make sure the variable date is numeric in the input dataset.

proc ds2;
    thread work.th_ieb / overwrite = yes;
        dcl double beg_jahr;
        method run();
            set {
                select id, birthdt
                from data
            };
            if first.id then do;
                beg_jahr = year(birthdt);
                output;
            end;
        end;
    endthread;
run;
quit;

      

0


source







All Articles