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.);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.