I have a Date column that has been formatted as a number and the datetime is reflected as a number, eg 1753920000
I need to convert this to a date format, eg 20151001 or 01OCT.
Thanks
Since valid_end_dt1 contains valid SAS datetime values (otherwise the datetime20. format would never work), you can apply the datepart function directly to it. No need for the double conversion.
So your code would be
data VALID_DATE;
set source table;
valid_end_date_1=datepart(valid_end_dt1);
format valid_end_date_1 date5.;
run;
data _NULL_;
a='22JUN2019:23:14:12'dt;
put a=;
put a= datetime.;
b=datepart(a);
put b=;
put b= date9.;
run;
I solved the problem as follows:
data VALID_DATE;
set source table;
valid_end_date_1=datepart(input(put(valid_end_dt1,datetime20.),datetime20.));
format valid_end_date_1 date5. ;
run;
Results:
VALID_END_DT1 | VALID_END_DATE_1 |
1753920000 | 31-Jul |
1753920000 | 31-Jul |
Since valid_end_dt1 contains valid SAS datetime values (otherwise the datetime20. format would never work), you can apply the datepart function directly to it. No need for the double conversion.
So your code would be
data VALID_DATE;
set source table;
valid_end_date_1=datepart(valid_end_dt1);
format valid_end_date_1 date5.;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.