- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%put %sysfunc(intnx(day,%sysfunc(today()),-1),date9.);
or
%put %sysfunc(putn(%eval(%sysfunc(today())-1),date9.));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this?
%PUT %SYSFUNC(PUTN(%SYSFUNC(INTNX(DAY,%SYSFUNC(TODAY()),-1)),date9.));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The command worked! Thank you for the support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The command
"data _null_;
call symput('YTDAY',put(today()-1,date9.));
run;
%put &YTDAY.;"
worked! Thank you for the support!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/* 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%put %sysfunc(intnx(day,%sysfunc(today()),-1),date9.);
or
%put %sysfunc(putn(%eval(%sysfunc(today())-1),date9.));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
YESTERDAY=DATE()-1;
CALL SYMPUT('YESTERDAY',PUT(YESTERDAY,DATE9.));
RUN;
%PUT &YESTERDAY;