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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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