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)
%put %sysfunc(intnx(day,%sysfunc(today()),-1),date9.);
or
%put %sysfunc(putn(%eval(%sysfunc(today())-1),date9.));
How about this?
%PUT %SYSFUNC(PUTN(%SYSFUNC(INTNX(DAY,%SYSFUNC(TODAY()),-1)),date9.));
The command worked! Thank you for the support.
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.
The command
"data _null_;
call symput('YTDAY',put(today()-1,date9.));
run;
%put &YTDAY.;"
worked! Thank you for the support!
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);
/* 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.
%put %sysfunc(intnx(day,%sysfunc(today()),-1),date9.);
or
%put %sysfunc(putn(%eval(%sysfunc(today())-1),date9.));
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.