BookmarkSubscribeRSS Feed
Robert_
Calcite | Level 5

Hello,
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, CreationDate_n field.
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;
1 REPLY 1
JosvanderVelden
SAS Super FREQ

Have you investigated using functions?

Ex.

proc ds2;
data _null_; 
   dcl date ds2d having format YYMMDD10.;
   dcl time ds2t having format TIME18.9;
   dcl timestamp ds2dt having format DATETIME28.9;
   dcl double d t ts;
   method init();
      d = 19358;
      ds2d = to_date(d);
      ds2t = to_time(d);
      ds2dt = to_timestamp(d);
      put ds2d= ds2t= ds2dt=;
   end;
enddata;
run;
quit;

This doesn't solve the issue for converting the datetime string though. Sorry.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 220 views
  • 0 likes
  • 2 in conversation