06-08-2018 04:02 AM
I need your help in year format.
I have a data set which has got commencement_dt as 23MAY2013:00:00:00 which is in DATETIME20. format, from the same commencement_dt i want to get only year. Is there a way where i can get only year format or by creating another variable only for year to appear.
Appreciate your help.
06-08-2018 04:04 AM
Use the datepart() and year() functions:
data have; input commencement_dt :datetime20.; format commencement_dt datetime20.; cards; 23MAY2013:00:00:00 ; run; data want; set have; commencement_year = year(datepart(commencement_dt)); run;
06-08-2018 05:10 AM
06-08-2018 05:15 AM
@katkarparam only wanted to show that SAS accepts any longer string as a date literal, as long as the start is a SAS date:
data test; x1 = '01jan2018xxxxxxxxxxx'd; format x1 yymmddd10.; run;
For existing data, use a data step similar to mine.
06-08-2018 05:28 AM - edited 06-08-2018 05:29 AM
Yes, you are right. data test;
x1 = '01jan2018xxxxxxxxxxx'd;
format x1 yymmddd10.;
Output dataset contain