DATA Step, Macro, Functions and more

Date Variable to be put into macro in %let.

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

Date Variable to be put into macro in %let.

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;


Accepted Solutions
Solution
‎04-07-2015 11:23 AM
Super User
Posts: 19,878

Re: Date Variable to be put into macro in %let.

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


All Replies
Solution
‎04-07-2015 11:23 AM
Super User
Posts: 19,878

Re: Date Variable to be put into macro in %let.

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

Contributor
Posts: 61

Re: Date Variable to be put into macro in %let.

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

Super User
Posts: 19,878

Re: Date Variable to be put into macro in %let.

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.

Contributor
Posts: 61

Re: Date Variable to be put into macro in %let.

Thanks for the clarification.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 2329 views
  • 1 like
  • 2 in conversation