DATA Step, Macro, Functions and more

Macro function to output yesterday's date

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Macro function to output yesterday's date

Hello. May I know how to output yesterday's date?

To output today's date, what I do is execute "%put %sysfunc(today(),date);"

141  %put %sysfunc(today(),date);

25JUN14

I tried yesterday's date by revising my code to "%put %sysfunc(today()-1,date);" but I am receiving an error:

ERROR: Expected close parenthesis after macro function invocation not found.

1,date)

This also didn't work "%put %sysfunc((today(),date)-1);":

ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference.

today(),date)-1)


Accepted Solutions
Solution
‎06-25-2014 08:01 AM
Super Contributor
Posts: 275

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser

%put %sysfunc(intnx(day,%sysfunc(today()),-1),date9.);

or

%put %sysfunc(putn(%eval(%sysfunc(today())-1),date9.));

View solution in original post


All Replies
Super Contributor
Posts: 312

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser

How about this?

%PUT %SYSFUNC(PUTN(%SYSFUNC(INTNX(DAY,%SYSFUNC(TODAY()),-1)),date9.));

Contributor
Posts: 22

Re: Macro function to output yesterday's date

Posted in reply to Scott_Mitchell

The command worked! Thank you for the support.

Super User
Super User
Posts: 9,599

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser

Hi,

I don't have SAS currently, so can't check.  But I think you would need:

%put %sysfunc(%eval(today()-1),date);

Or you could do:

data _null_;

     call symput('YTDAY',put(today()-1,date9.));

run;

%put &YTDAY.;

There's a few other options, depends on how you are using this date later.

Contributor
Posts: 22

Re: Macro function to output yesterday's date

The command

"data _null_;

     call symput('YTDAY',put(today()-1,date9.));

run;

%put &YTDAY.;"

worked! Thank you for the support!

Super User
Posts: 5,881

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser

Macro is strictly about text, so if you wish to do numerical calculations, you need to explicitly tell the macro processor that.

%put %eval(%sysfunc(today()) - 1);

Data never sleeps
Contributor
Posts: 46

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser

/* Creating Global Macro Variables  */

data _null_;

call symput('MAR14',put(intnx('month',today(),-3),monyy5.));                 

call symput('APR14',put(intnx('month',today(),-2),monyy5.));
call symput('MAY14',put(intnx('month',today(),-1),monyy5.));

call symput('JUN14',put(intnx('month',today(),-0),monyy5.));    /* CURRENT MONTH */
call symput('JUL14',put(intnx('month',today(),+1),monyy5.));      

call symput('AUG14',put(intnx('month',today(),+2),monyy5));
call symput('SEP14',put(intnx('month',today(),+3),monyy5.)); 

call symput('OCT14',put(intnx('month',today(),+4),monyy5.));       

RUN;

%put &MAR14;

%put &APR14;

%put &MAY14;

%put &JUN14; /* CURRENT MONTH */

%put &JUL14;

%put &AUG14;

%put &SEP14;

%put &OCT14;

1. In the Same way u can create Date and any kind of Date related Values. Just need to change output FORMAT.

EX:-  ddmmyy10. or Date9.

Solution
‎06-25-2014 08:01 AM
Super Contributor
Posts: 275

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser

%put %sysfunc(intnx(day,%sysfunc(today()),-1),date9.);

or

%put %sysfunc(putn(%eval(%sysfunc(today())-1),date9.));

Occasional Contributor
Posts: 18

Re: Macro function to output yesterday's date

Posted in reply to 01SASUser
DATA _NULL_;
YESTERDAY=DATE()-1;
CALL SYMPUT('YESTERDAY',PUT(YESTERDAY,DATE9.));
RUN;
%PUT &YESTERDAY;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 20816 views
  • 10 likes
  • 7 in conversation