BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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

3 REPLIES 3
MadhuKorni
Quartz | Level 8

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.
 

Tom
Super User Tom
Super User

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.

 

PaigeMiller
Diamond | Level 26

@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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1637 views
  • 1 like
  • 4 in conversation