One way:
data have; input Date; datalines; 201304 201406 201409 201412 201311 ; data want; set have; new_date = input(put(date,f6.),yymmn6.); format new_date yymms7.; run;
Input works with character values so need to use the Put function to create such and the yymmn informat reads year month values.
Note that the New_date variable will have a presumed day of the month of 1.
One way:
data have; input Date; datalines; 201304 201406 201409 201412 201311 ; data want; set have; new_date = input(put(date,f6.),yymmn6.); format new_date yymms7.; run;
Input works with character values so need to use the Put function to create such and the yymmn informat reads year month values.
Note that the New_date variable will have a presumed day of the month of 1.
In SAS the word FORMAT means the instructions for how to convert the values into text, for example when printing the values in a report.
SAS has only two types of variables floating point numbers and fixed length character strings. Your original values are numbers, like 201,304 or 201,412. SAS stores DATE values as the number of days since 1960, so over 200 thousand days would be almost 500 years into the future.
So do you want to convert those numbers into character strings? Or date values?
data have;
input date;
cards;
201304
201406
201409
201412
201311
;
data want;
set have;
length new_date $7. date_value 8;
new_date=put(date,z6.);
new_date=catx('/',substr(new_date,1,4),substr(new_date,5));
date_value=input(put(date,z6.),yymmn6.);
format date_value YYMMS7.;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.