DATA Step, Macro, Functions and more

intnx function in a macro variable

Accepted Solution Solved
Reply
Contributor
Posts: 49
Accepted Solution

intnx function in a macro variable

Hi,

use the intnx function in a macro variable:

 

%let start   = %sysfunc(intnx(MONTH,%sysfunc(today()),-1,SAME),DDMMYYS10.);

 

It, works...but I would like to know if is there another way to do the same operation?


Accepted Solutions
Solution
‎11-21-2016 04:16 AM
Super User
Posts: 6,936

Re: intnx function in a macro variable

You can use my data step in that main program.

I guess you will %include that in all your programs or autoexec's. Data steps in %include'd files will work just as if they were written directly in the calling program.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,936

Re: intnx function in a macro variable

My preferrred method is to use a data _null_ step and call symput:

data _null_;
start = intnx('MONTH',today(),-1,'SAME');
call symput('start',put(start,DDMMYYS10.));
run;

So all the calculations are done in pure data step language and easier to read, because you don't have to care for all the %sysfunc's.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 49

Re: intnx function in a macro variable

Thanks,

but I need to use it outside the data step, because I write the main program.

 

 

 

 

Super User
Posts: 6,936

Re: intnx function in a macro variable

My data _null_ step delivers eactly the same result that your %let does.

Keep this in mind:

if you write a %let in a data step, it will not be executed in the data step (!!!). Instead it will be executed upon the fetching of the code, so logically it is the same as if you wrote it immediately before the data step.

 

BTW, what do you mean by "main program"?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 49

Re: intnx function in a macro variable

Yes,

thank for you answer and for your help,

for me,

the main Program is a file where I put all important macro variable and the libname for the path of several programs *.sas

 

 

 

 

Solution
‎11-21-2016 04:16 AM
Super User
Posts: 6,936

Re: intnx function in a macro variable

You can use my data step in that main program.

I guess you will %include that in all your programs or autoexec's. Data steps in %include'd files will work just as if they were written directly in the calling program.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 49

Re: intnx function in a macro variable

Ah,

ok thanks!!

Super User
Posts: 6,936

Re: intnx function in a macro variable

[ Edited ]

To further elaborate:

%include is a macro (pre-processor) statement. As soon as it is encountered, the included file is read and placed in the input buffer of the SAS interpreter in place of the %include statement. So you can use any SAS code in a file that is to be %include'd.

It's just that, after the include is performed, the resulting code needs to be syntactically correct and make sense.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 553 views
  • 1 like
  • 2 in conversation