I'm creating macro variables to store dates. I want these dates to be set to certain days if the code is run on Monday morning. If the code isn't run on Monday morning, I want the dates to be set to different days. I thought I was doing this correctly with my code below. When I run my code, my date macro variables are indeed returned. However, if I change my if statement (e.g. change if weekday = 2 to if weekday = 3) and then run my code, I'm returned dates that are intended to be set if weekday = 2 is returned (i.e. returned dates aren't changed, despite making change to if statement). If I run my code again (without making any changes to code after the initial change of weekday = 2 to weekday = 3), I'm then returned the dates that are set if weekday = 3. Why do I have to run my code twice after making a change to the if statement for the logic to work and to return the intended dates? data _null_;
/*if program runs on Monday before noon, then set reportdate to Saturday and priordate to Friday*/
if hour(time()) < 12 and weekday(today()) = 2 then do;
ReportDate = put(intnx('day',TODAY(),-2),date9.); call symputx('ReportDate',"'"||ReportDate||"'");
PriorDate = put(intnx('day',TODAY(),-3),date9.); call symputx('PriorDate',"'"||PriorDate||"'");
end;
/*if program doesn't run Monday morning, then set reportdate to current day and priordate to yesterday*/
else do;
ReportDate = put(intnx('day',TODAY(),0),date9.); call symputx('ReportDate',"'"||ReportDate||"'");
PriorDate = put(intnx('day',TODAY(),-1),date9.); call symputx('PriorDate',"'"||PriorDate||"'");
end;
%put &ReportDate; %put &PriorDate;
run;
... View more