Help using Base SAS procedures

How to convert to Datetime?

Reply
Contributor
Posts: 74

How to convert to Datetime?

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
Super Contributor
Posts: 394

Re: How to convert to Datetime?

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
Regular Contributor
Posts: 165

Re: How to convert to Datetime?

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.
PROC Star
Posts: 7,492

Re: How to convert to Datetime?

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
Ask a Question
Discussion stats
  • 3 replies
  • 112 views
  • 0 likes
  • 4 in conversation