- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have all numerical values like how SAS counts them in days since Jan 1, 1960. I need SAS to show them to me in the format DDMMMYYhh:mm:ss. I tried the following but to no avail
data work.one;
set work.two;
format datetimevar DATETIME16.0;
run;
What am I missing?
Thank you.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
From what I read about STATA it seems to be saying the %tc is for numbers stored in Milliseconds. Try dividing the numbers you see in your SAS variable by 1000 and then apply a DATETIME. type format.
Your example doesn't look right as when I try that number I get a date in 1997.
26 data _null_;
27 x = '22aug2000:11:00:00'dt;
28 put x= x= datetime19. ;
29 y = 1.1863584E12 ;
30 put y= ;
31 x = y/1000 ;
32 put x= x= datetime19. ;
33 run;
x=1282561200 x=22AUG2000:11:00:00
y=1.1863584E12
x=1186358400 x=05AUG1997:00:00:099
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
datetimes are seconds from jan 1, 1960 not days.
That looks like the default format, so I'm guessing somethings wrong with your dates, eg dates, not datetime or character variables instead of number.
This works as expected:
data one;
var1=dhms(18754, 0, 0, 0);
var2=var1;
format var2 datetime.;
run;
proc print;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As Reeza suggests, your data must be a datetime value to use the DATETIMEw.d format.
If your data is a date value (not datetime), you will have to convert it to a datetime value (e.g. via the DHMS function as Reeza suggests) if you want to apply the DATETIMEw.d format.
If data is a date value, and you just want to display the date in human-readable form and you aren't concerned about hours/minutes/seconds, then use a format like DATE9.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the suggestions.
My data is imported from a Stata file and has the datetime variable stored as a number (type: double, format: %tc). After importing, in the temporary SAS dataset, this variable shows up as e.g. 1.1863584E12 which is nothing but 22aug2000 11:00:00. as it shows in the Stata dataset when I open it in the table mode.
Do I still need to convert it to datetime using DHMS and then apply the datetimew.d format?
Thanks a bunch. This is really simple, I know but I have just started.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
From what I read about STATA it seems to be saying the %tc is for numbers stored in Milliseconds. Try dividing the numbers you see in your SAS variable by 1000 and then apply a DATETIME. type format.
Your example doesn't look right as when I try that number I get a date in 1997.
26 data _null_;
27 x = '22aug2000:11:00:00'dt;
28 put x= x= datetime19. ;
29 y = 1.1863584E12 ;
30 put y= ;
31 x = y/1000 ;
32 put x= x= datetime19. ;
33 run;
x=1282561200 x=22AUG2000:11:00:00
y=1.1863584E12
x=1186358400 x=05AUG1997:00:00:099
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Tom, Fugue and Reeza.
The last solution totally worked.