BookmarkSubscribeRSS Feed
ren2010
Obsidian | Level 7
My code is below, and I am trying to convert a MMDDYY var to DATETIME19.,but getting unreasonable value. example:

data _null_;
x=today();
put x= date.;
put x1= datetime.;
run;

This code produces the following:

X=12/01/2010
X1=01JAN60:04:02:23

is there any way to avoid the non valid value of X1?
Please help
3 REPLIES 3
Tim_SAS
Barite | Level 11
The today() function returns a date value, not a datetime value. Use the datetime() function instead.

http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000200627.htm Message was edited by: Tim@SAS
RickM
Fluorite | Level 6
Date variables are days since 1/1/1960. Datetime variables are seconds since 1/1/1960. So lets say x=2. If we display x with a date format we would ge two days past 1/1/1960 (1/3/1960). If we display x with a datetime format we get two seconds past midnight on 1/1/1960 00:00:02.
art297
Opal | Level 21
You already have the answer you needed. Now, if you want to learn more about working with dates, times and datetimes in SAS, take a look at:

http://www2.sas.com/proceedings/sugi25/25/btu/25p058.pdf

HTH,
Art

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 872 views
  • 0 likes
  • 4 in conversation