BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
01SASUser
Fluorite | Level 6

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)

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10

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

or

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

View solution in original post

8 REPLIES 8
Scott_Mitchell
Quartz | Level 8

How about this?

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

01SASUser
Fluorite | Level 6

The command worked! Thank you for the support.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

01SASUser
Fluorite | Level 6

The command

"data _null_;

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

run;

%put &YTDAY.;"

worked! Thank you for the support!

LinusH
Tourmaline | Level 20

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
sas_lak
Quartz | Level 8

/* 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.

slchen
Lapis Lazuli | Level 10

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

or

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

kanivan51
Obsidian | Level 7
DATA _NULL_;
YESTERDAY=DATE()-1;
CALL SYMPUT('YESTERDAY',PUT(YESTERDAY,DATE9.));
RUN;
%PUT &YESTERDAY;

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
  • 8 replies
  • 48920 views
  • 10 likes
  • 7 in conversation