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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 616 views
  • 0 likes
  • 4 in conversation