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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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