DATA Step, Macro, Functions and more

SAS macro vars-Today,yesterday,same day in the prior month from yesterday

Reply
Frequent Contributor
Posts: 142

SAS macro vars-Today,yesterday,same day in the prior month from yesterday

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.;

Frequent Contributor
Posts: 77

Re: SAS macro vars-Today,yesterday,same day in the prior month from yesterday

[ Edited ]

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.
 

Super User
Super User
Posts: 8,111

Re: SAS macro vars-Today,yesterday,same day in the prior month from yesterday

[ Edited ]

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.

 

Respected Advisor
Posts: 3,019

Re: SAS macro vars-Today,yesterday,same day in the prior month from yesterday


@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.

--
Paige Miller
Ask a Question
Discussion stats
  • 3 replies
  • 54 views
  • 1 like
  • 4 in conversation