BookmarkSubscribeRSS Feed
robulon
Quartz | Level 8

Hi,

 

I'm a bit frustrated with myself at not being able to figure this out but there you. Where I work creates daily batch files except for on a Sunday. I want to be able to identify the last created batch file for a month.

 

I could (and indeed have been) using: -

 

if weekday(intnx('month',current_month, 1) - 1) ne 1 then mthend = intnx('month',current_month, 1) -1;

else mthend = intnx('month',current_month, 1) -2;

 

But was hoping for something a bit more aesthetically pleasing. I thought I could use a variation on

 

last_month_busday = intnx('WEEKDAY', intnx('MONTH', date, -1, 'END'), 0);

 

but replacing 'WEEKDAY' with 'WEEKDAY234567w' which I thought would omit Sundays from consideration but this is not working. If anyone could suggest a way to do this, I would really appreciate it.

 

Many thanks,

Rob

 

 

 

 

 

 

2 REPLIES 2
mkeintz
PROC Star

Not pretty, but this is a single statement:

 

data _null_;
  current_date=mdy(3,7,2019);
  last_bus_day=intnx('month',current_date,0,'E') - (weekday(intnx('month',current_date,0,'E'))=1);
  put (_all_) (=weekdate20.);
run;

It  might make sense for other users  of the program to see two lines:

 

data _null_;
  current_date=mdy(3,7,2019);
  last_bus_day=intnx('month',current_date,0,'E');
  if weekday(intnx('month',current_date,0,'E'))=1 then last_bus_day=last_bus_day-1;
  put (_all_) (=weekdate20.);
run;

Editted note:

In the second block of code, I should have put:

   if weekday(last_bus_day)=1 then last_bus_day=last_bus_day-1; 

instead of the long IF statement I entered.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
robulon
Quartz | Level 8
Thanks for this, it's not exactly what I was after but has shown me a couple of new things I haven't seen before which is always good.