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.);
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.