BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
EarlyCode
Fluorite | Level 6

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.)

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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'

View solution in original post

4 REPLIES 4
Reeza
Super User

Look at the weekday interval for intnx function instead of day Smiley Happy

EarlyCode
Fluorite | Level 6

%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.

Reeza
Super User

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'

EarlyCode
Fluorite | Level 6

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:

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2451 views
  • 3 likes
  • 2 in conversation