BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PierreYvesILY
Pyrite | Level 9

dear SAS experts,

 

I have numeric variables for YEAR (ex: 2021) and MONTH (ex: 5) and I want to get a new variable like: YYYYMM in NUMERIC, where the month Always on 2 Digits is ; for instance: 202105.

 

How can I get this?

 

thanks in Advance,

regards

PY

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

So you want a numeric variable that contains YYYYMM in which case this will do it:

 

data have;
	input month  year ;
datalines;
05 2021
04 2020
03 2019
;

data want ;
	set have;
	want=year*100+month ;
	put year= month= want= ;
run;

Although I would recommend you convert your numeric month/year into a SAS Date value and then format that, as follows:

data have;
	input month  year ;
datalines;
05 2021
04 2020
03 2019
;

data want ;
	set have;
	sasDate=mdy(month,01,year) ;
	want=putn(sasDate,"yymmn6.") ;
	put year= month= sasDate= want= ;
run;

View solution in original post

1 REPLY 1
AMSAS
SAS Super FREQ

So you want a numeric variable that contains YYYYMM in which case this will do it:

 

data have;
	input month  year ;
datalines;
05 2021
04 2020
03 2019
;

data want ;
	set have;
	want=year*100+month ;
	put year= month= want= ;
run;

Although I would recommend you convert your numeric month/year into a SAS Date value and then format that, as follows:

data have;
	input month  year ;
datalines;
05 2021
04 2020
03 2019
;

data want ;
	set have;
	sasDate=mdy(month,01,year) ;
	want=putn(sasDate,"yymmn6.") ;
	put year= month= sasDate= want= ;
run;