BookmarkSubscribeRSS Feed
anagham
Calcite | Level 5

Hi,

 

I need yesterdays date in format yyyy-mm-dd along with single quotes e.g. '2020-02-28'. 

Also, it should exclude saturday sunday. So if I am running job on Monday, it should take friday's date as input.

 

I have tried multiple things. I am getting correct yesterdays date with below(not included sat-sun logic yet), but I need single quotes along with it.

 

%sysfunc(PUTN(%eval(%sysfunc(date())-1),yymmdd10.))

 

Please help.

 

5 REPLIES 5
andreas_lds
Jade | Level 19

Try

data _null_;
   lastDay = today() - 1;
   
   call symputx('lastDay', cats("'", put(lastDay, yymmdd10.), "'"));
run;

Hint for moving "lastDay" to last Friday: the function weekday returns 1 for Sunday and 7 for Saturday,

Patrick
Opal | Level 21

Via a data _null_ step.

data _null_;
  prev_weekdate=intnx('weekday',date(),-1);
  call symputx('mydate',cats("'",put(prev_weekdate,yymmdd10.),"'"));
  stop;
run;
%put &mydate;

Or following your sample code as a big fat spaghetti.

%put %unquote(%str(%')%sysfunc(intnx(weekday,%sysfunc(date()),-1),yymmdd10.)%str(%'));    

 

PaigeMiller
Diamond | Level 26

One more solution: Let the QUOTE() function have all the fun!

 

data _null_;
   call symputx('lastDay', quote(put(today()-1,yymmdd10.),"'"));
run;
--
Paige Miller
PaigeMiller
Diamond | Level 26

Or, if you really want to do it entirely with the macro processor and not via CALL SYMPUTX

 

%let lastday = %nrstr(%')%sysfunc(PUTN(%eval(%sysfunc(date())-1),yymmdd10.))%nrstr(%');

which works but isn't particularly easy to read. 

--
Paige Miller
anagham
Calcite | Level 5

Thank you all for the help..It was helpful. 🙂

I will share my code which worked properly in my case.

 

Thanks.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1663 views
  • 0 likes
  • 4 in conversation