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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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