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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 597 views
  • 1 like
  • 2 in conversation