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?
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.
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.
Thanks,
but I need to use it outside the data step, because I write the main program.
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"?
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
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.
Ah,
ok thanks!!
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.