Search code examples
sassas-ds2

Datastep2: converting string to timestamp


I'm struggling with converting a string to a timestamp. This is quite easy in normal Datastep, but not for me in DS2. How would I have to modify the DS2 code so that I get the same result as in the normal datastep for the field CreationDate_n . Many thanks for your help!

data Testdaten;
    attrib
           CreationDate_c length= $40 
           CreationDate_n length= 8   format=DATETIME25.6;


    CreationDate_c='2023-09-14T07:07:41+02:00';
    CreationDate_n=input(CreationDate_c,ANYDTDTM.);

run;


proc ds2;
data _null_;

    dcl timestamp CreationDate having format DATETIME25.6;

    method run();
        set Testdaten;

            CreationDate= inputn(CreationDate_c,'ANYDTDTM.') ;

            put CreationDate=;

    end;
enddata;
run;
quit;

Solution

  • The inputn() function returns a numerical value.

    Change the declaration to double

    proc ds2;
    data want;
        dcl double CreationDate having format DATETIME25.6;
        method run();
            set Testdaten;
                CreationDate= inputn(CreationDate_c,'ANYDTDTM.') ;
                put CreationDate=;
        end;
    enddata;
    run;
    quit;
    

    From the documentation

    In PROC DS2, when you submit DS2 statements, all DS2 language data types are supported. For information about the DS2 data types, see SAS DS2 Language Reference. However, when reading and creating data, the DS2 data types are translated to and from the data types of the target data source. When submitting statements to read or to create a SAS data set, SPD Engine data set, or SPD Server table, DS2 data types are translated to and from the SAS numeric and SAS character data types. The following table lists the DS2 data types and how they are translated to and from SAS data types: ...