Data is currently stored as date format, YYYYMM. However I would like to create a text column with just year and month. Meaning to say YYMM, I know this is not a good way to store data however I require it in that format. Meaning to say for YYYYMM = 201906, desired output = 1906. YYYYMM = 202006, desired output = 2006. YYYYMM = 200606, desired output = 0606.
data have; infile datalines missover; input yymm :yymmn6.; format yymm yymmn6.; datalines; 201904 201807 201912 202005 ;
If you just want to have the existing variable displayed without the century then just change the width of the format.
format yymm yymmn4.;
If instead want to create a character variable then use a PUT() function call.
desired_output = put(yymm,yymmn4.);
data have; infile datalines missover; input yymm :yymmn6.; format yymm yymmn6.; want=cats(put(yymm,year2.),put(month(yymm),z2.)); datalines; 201904 201807 201912 202005 ;
data have;
infile datalines missover;
input yymm :yymmn6.;
format yymm yymmn4.;
datalines;
201904
201807
201912
202005
;
proc print; run;
If you just want to have the existing variable displayed without the century then just change the width of the format.
format yymm yymmn4.;
If instead want to create a character variable then use a PUT() function call.
desired_output = put(yymm,yymmn4.);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.