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;
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
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
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
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.
Thanks for the clarification.
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.
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.