I have my date variable set as:
%let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(day,%sysfunc(today()) ,-1)),yymmdd10.))%str(%');
Which is serving it's purpose to create a variable "DATE" that I use in the query to always check for new activity from yesterday. However on Mondays, I need to check for new activity over the whole weekend. So it needs to be
%let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(day,%sysfunc(today()) ,-3)),yymmdd10.))%str(%');
(Which on Monday should return Friday's date.)
Currently it's just making that minor manual adjustment on Mondays, but it seems like I should be able to have the adjustment occur automatically with an IF statement.
But I'm not sure how to set the IF statement so it recognizes to only use the second one on Mondays and on Tuesday through Friday to use the first.
(That is my main concern to avoid needing to manually adjust it every Monday, but should someone have a trick to have it make a similar adjustment for holidays to eliminate that manual adjustment, that would be awesome.)
I was thinking of replacing DAY with WEEKDAY
SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition
%let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(DAY,%sysfunc(today()) ,-1)),yymmdd10.))%str(%');
%put &date.;
VS
%let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(WEEKDAY,%sysfunc(today()) ,-1)),yymmdd10.))%str(%');
%put &date.;
72 %let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(DAY,%sysfunc(today())
72 ! ,-1)),yymmdd10.))%str(%');
73 %put &date.;
'2014-12-28'
74
75 %let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(WEEKDAY,%sysfunc(today())
75 ! ,-1)),yymmdd10.))%str(%');
76 %put &date.;
'2014-12-26'
Look at the weekday interval for intnx function instead of day
%LET DAY=%SYSFUNC(putn( %sysfunc(today()) ,WEEKDAY.));
%PUT DAY=&DAY;
%MACRO Monday_Check;
%IF &day=2
%THEN %LET DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(day,%sysfunc(today()) ,-1)),yymmdd10.))%str(%');
%ELSE %LET DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(day,%sysfunc(today()) ,-3)),yymmdd10.))%str(%');
Run;
%Mend Monday_Check;
%Monday_Check;
%PUT Yesterday= &DATE Day= &Day;
I'm missing something, I'm not sure if it's in the macro statement or the IF statement. But it's not running correctly.
I was thinking of replacing DAY with WEEKDAY
SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition
%let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(DAY,%sysfunc(today()) ,-1)),yymmdd10.))%str(%');
%put &date.;
VS
%let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(WEEKDAY,%sysfunc(today()) ,-1)),yymmdd10.))%str(%');
%put &date.;
72 %let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(DAY,%sysfunc(today())
72 ! ,-1)),yymmdd10.))%str(%');
73 %put &date.;
'2014-12-28'
74
75 %let DATE=%str(%')%sysfunc( putn( %sysfunc(intnx(WEEKDAY,%sysfunc(today())
75 ! ,-1)),yymmdd10.))%str(%');
76 %put &date.;
'2014-12-26'
So by obsessing over the idea of a if statement I was making it more difficult on myself then it needed to be...
Sounds about right for me... :smileyblush:
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.
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.