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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 772 views
  • 1 like
  • 2 in conversation