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

Hi, All,

Based on the current date batch I have (20120229) I want to go back 24 months and grab the month end (20100228).

Right now, I can do it with INTNX and CALL SYMPUT. At the same time, I want to do the same thing with %let. However,

I am a little lost and confused and don't know how to get it.

Please offer suggestions if you can, Thanks.

Joe

/*WORKING*/

%let batch=20120229;

data _null_;

oldbatch=INTNX('month',input (put(&batch,8.), YYMMDD8.),-24, 'end');

call symput ('batch2',trim(left(put(oldbatch,yymmddn8.))));

run;

%put check the value of: &batch2;

/*NOT WORKING*/

%let batch_c= %sysfunc (putn(&batch,8.));

%let batch_d= %sysfunc (inputn(&batch_c,YYMMDD8.));

%let batch3=  %sysfunc(intnx('month', &batch_d, -24, 'end'));;

%put check the value of: &batch_c, &batch_d, &batch3;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You don't need the quotes around the month/end in your last batch3 macro variable declaration, and apply your format in the %sysfunc otherwise it's a SAS date so a number.

57   %let batch=20120229;

58   %let batch_c= %sysfunc (putn(&batch,8.));

59   %let batch_d= %sysfunc (inputn(&batch_c,YYMMDD8.));

60   %let batch3=  %sysfunc(intnx(month, &batch_d, -24, end), yymmddn8.);;

61

62   %put check the value of: &batch_c, &batch_d, &batch3;

check the value of: 20120229, 19052, 20100228

View solution in original post

4 REPLIES 4
Reeza
Super User

You don't need the quotes around the month/end in your last batch3 macro variable declaration, and apply your format in the %sysfunc otherwise it's a SAS date so a number.

57   %let batch=20120229;

58   %let batch_c= %sysfunc (putn(&batch,8.));

59   %let batch_d= %sysfunc (inputn(&batch_c,YYMMDD8.));

60   %let batch3=  %sysfunc(intnx(month, &batch_d, -24, end), yymmddn8.);;

61

62   %put check the value of: &batch_c, &batch_d, &batch3;

check the value of: 20120229, 19052, 20100228

jiangmi
Calcite | Level 5

Thanks, Reeza,

It works now.

I am not good with sas dates. I actually checked the online document about INTNX:

SAS(R) 9.3 Functions and CALL Routines: Reference

and copied a sample into my code. In the sample, they had quotes.

Anyway, Thanks a lot.

Joe

Reeza
Super User

If you use INTNX in a SQL or data step it requires the quotes. The macro processor requires no quotes. This is true of other text parameters for functions as well, not just iNTNX.

jiangmi
Calcite | Level 5

Thanks for the clarification.

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!

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
  • 4 replies
  • 14521 views
  • 1 like
  • 2 in conversation