Hello
I want to create 3 sas macro varaibles :Today,yesterday,same day in the prior month from yesterday.
data _null_;
call symputx('Today', PUT(intnx('DAY',today(),0), date9.));
* Today;
call symputx('d_yesterday', put(today()-1, date9.));
* yesterday;
call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.));
*last month same day of yesterday;
RUN;
%put &Today.;/*10JUL2018*/
%put &d_yesterday.;/*09JUL2018*/
%put &beta.;/*09JUN2018*/
When I did it in another way I received an error.
May someone tell me please why is the error?
%let d_today=%sysfunc(today());
%put &d_today.;
data _null_;
call symputx('d_yesterday', PUT(intnx('DAY',&d_today.,-1), date9.));
* yesterday;
call symputx('beta', PUT(intnx('DAY',%SYSFUNC(&d_today.),-1), date9.));
*last month same day of yesterday;
RUN;
%put &d_yesterday.;
%put &beta.;
1.Remove %sysfunc in your datastep code.
2.intnx is not required in your code.
Remove %sysfunc and intnx functions in the belowline of code
call symputx('beta', PUT(intnx('DAY',%SYSFUNC(&d_today.),-1), date9.));
call symputx('beta', PUT(intnx('DAY',&d_today.,-1), date9.));
call symputx('beta', PUT(&d_today.-1, date9.));
Above two lines of code gives the same result.
Macro processing is just simple text replacement. Look at what you posted.
@Ronein wrote:
When I did it in another way I received an error.
May someone tell me please why is the error?
%let d_today=%sysfunc(today());
%put &d_today.;
data _null_;
call symputx('beta', PUT(intnx('DAY',%SYSFUNC(&d_today.),-1), date9.));
RUN;
So you set the macro variable D_TODAY to some 5 digit integer string representing the number of days since 1960. For today that is the string 21375.
You then used it to as the name of the SAS function for %SYSFUNC() macro function to call. There is no function named 21375. And anyway you left off the required () after the function name.
@Ronein wrote:
Hello
I want to create 3 sas macro varaibles :Today,yesterday,same day in the prior month from yesterday.
data _null_;
call symputx('Today', PUT(intnx('DAY',today(),0), date9.));
* Today;
call symputx('d_yesterday', put(today()-1, date9.));
* yesterday;
call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.));
*last month same day of yesterday;
RUN;
%put &Today.;/*10JUL2018*/
%put &d_yesterday.;/*09JUL2018*/
%put &beta.;/*09JUN2018*/
When I did it in another way I received an error.
May someone tell me please why is the error?
%let d_today=%sysfunc(today());
%put &d_today.;
data _null_;
call symputx('d_yesterday', PUT(intnx('DAY',&d_today.,-1), date9.));
* yesterday;
call symputx('beta', PUT(intnx('DAY',%SYSFUNC(&d_today.),-1), date9.));
*last month same day of yesterday;
RUN;
%put &d_yesterday.;
%put &beta.;
From now on, could you please post your code in the proper format, by clicking on the running man icon, then pasting your code into the window that opens? Thanks.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.