Hi,
i have a fairly simple question. I would like to use
proc sql in SAS to extract the last business day from a set of records.
Not sure how I can do that.
Any help is appreciated
Thank you!
So you want the last working day of each month ?
data have;
input date : date9.;
format date date9.;
cards;
29jan2016
29apr2016
31may2016
30jun2016
30jul2016
;
run;
proc sql;
select *
from have
where date=intnx('weekday',intnx('month',date,0,'e'),0);
quit;
Business day is a hard definition and not built into SAS because of various holidays around the world.
You can find the last weekday using the INTNX function, but its usually relative to some other day so I'm not sure what you're referencing. Use the WEEKDAY as the interval in INTNX along with the respective alignment to get the last one desired.
So you want the last working day of each month ?
data have;
input date : date9.;
format date date9.;
cards;
29jan2016
29apr2016
31may2016
30jun2016
30jul2016
;
run;
proc sql;
select *
from have
where date=intnx('weekday',intnx('month',date,0,'e'),0);
quit;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.