BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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