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.
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,
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(%'));
One more solution: Let the QUOTE() function have all the fun!
data _null_;
call symputx('lastDay', quote(put(today()-1,yymmdd10.),"'"));
run;
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.
Thank you all for the help..It was helpful. 🙂
I will share my code which worked properly in my case.
Thanks.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.