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

hi ,

below is the small snippet :

 

%let year_month=202201;
data try;
temp=&year_month.-1;
run;

I want my temp to be 202112 not 202200 . Can you please help me in give a quick solution.

 

Thanks in advance !

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You want it be a DATE type variable or just simple NUMERIC type variable ?

 

%let year_month=202201;
data try;
temp=intnx('month',input("&year_month.01",yymmdd10.),-1);
format temp yymmn6.;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Do you want it in a macro variable or a Data Step variable?

Ksharp
Super User

You want it be a DATE type variable or just simple NUMERIC type variable ?

 

%let year_month=202201;
data try;
temp=intnx('month',input("&year_month.01",yymmdd10.),-1);
format temp yymmn6.;
run;
maguiremq
SAS Super FREQ

I don't know if this is the best solution, but here's what I have.

 

%let yearmonth = %sysfunc(intnx(month, %sysfunc(inputn(202201, yymmn6.)),-1,e));
%put &yearmonth.;
82   %put &yearmonth.;
22645
Tom
Super User Tom
Super User

@maguiremq wrote:

I don't know if this is the best solution, but here's what I have.

 

%let yearmonth = %sysfunc(intnx(month, %sysfunc(inputn(202201, yymmn6.)),-1,e));
%put &yearmonth.;
82   %put &yearmonth.;
22645

Close.  If you want to generate the digit string in YYYYMM style then tell %SYSFUNC() to apply the YYMMN format to the value.

1725   %let yearmonth = %sysfunc(intnx(month, %sysfunc(inputn(202201, yymmn6.)),-1,e),yymmn6.);
1726   %put &=yearmonth;
YEARMONTH=202112

maguiremq
SAS Super FREQ
Always there with the better insight! Thanks, Tom!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1438 views
  • 4 likes
  • 5 in conversation