Hi All,
I use the following code to select the previous days date.
%let DateVAR = %sysfunc(intnx(day,%sysfunc(today()),-1),yymmddn8.);
I need to now select the previous days date for a report except when it is run on a Monday I need it to return the Fridays date.
So if the report is run on Monday 9 July 2018 the date returned will be 6 July 2018.
How do I change this code to do this or is there different code I will need to use.
Cheers
Dean
So when the program runs on Sunday, you still want to return Saturday's date (not Friday)?
It's much easier to follow if you use a DATA step and get rid of %SYSFUNC. It could look like this:
data _null_;
datevar = today() - 1;
if weekday(datevar) = 1 then datevar = datevar - 2;
call symputx('datevar', put(datevar, yymmddn8.));
run;
weekday rather than day as the interval?
Or I guess if it's only Monday, use an IFN/IFC inside it?
Hi @Reeza,
I have never used IFC/IFN - can you show me an example or direct me to some help please.
Ultimately I need to populate a Where statement like below.
WHERE Date = "&DateVAR."d
Thanks for your help.
Cheers
Dean
You can play with something like this
%let DateVAR = %sysfunc(today(),downame.);
%put &datevar;
%if &DateVAR=Monday %then .............more statements...;
So when the program runs on Sunday, you still want to return Saturday's date (not Friday)?
It's much easier to follow if you use a DATA step and get rid of %SYSFUNC. It could look like this:
data _null_;
datevar = today() - 1;
if weekday(datevar) = 1 then datevar = datevar - 2;
call symputx('datevar', put(datevar, yymmddn8.));
run;
Hi @Astounding,
The report is for weekdays only so don't want to return Saturdays or Sundays - am I right if I change the code to the below to remove Saturdays as well?
data _null_;
datevar = today() - 1;
if weekday(datevar) = 1 then datevar = datevar - 2;
else if weekday(datevar) = 7 then datevar = datevar - 1;
call symputx('datevar', put(datevar, yymmddn8.));
run;
Cheers
Dean
You get 100%.
You can try this:
%macro dtx;
%global rptdt;
%if %eval(%sysfunc(weekday(%sysfunc(today()))))=2 %then %let rptdt = %sysfunc(intnx(weekday, %sysfunc(today()), -1), mmddyy10.);
%else %let rptdt = %sysfunc(intnx(day, %sysfunc(today()), -1), mmddyy10.);
%mend dtx;
%dtx;
%put &rptdt;
@EEng Yes, if s/he wants only weekdays then the weekday is a better approach. It was the first suggestion s/he received as well, so I'm guessing that's not what they want.
Hi @Reeza,
Apologies as I didn't read your response properly - I thought that was a question - now I know what you meant, replace day with weekday.
I should have known better as your responses to queries are always very helpful.
Regards
Dean
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.