Hey,
I am exploring for code to calculate the the total no of working days in a month excluding sundays only.
i.e start date should be 1st date of every month and the end date should be last day of every month and calculate net working days in the current month. As the code should fetch the current month and calculate accordingly.
Thanks
Something like:
data want; do i=intnx('month',today(),0,'beginning') to intnx('month',today(),0,'end'); if weekday(i) ne 1 then tot=sum(tot,1); end; run;
Remove all days where the weekday() function returns Saturday or Sunday.
Remove all days that can somehow be detected with the SAS holiday() function.
Remove all days that are country-specific or otherwise happen on a fixed date (May 1st, Christmas, New Year).
How you do it depends on how you need to use the result in further code.
For instance, you could create a table for a whole year (or a given timespan), and then create a custom format off that.
You could then create a macro
%macro num_workdays(month,year);
%local i;
%let i = 0;
%do day = %sysfunc(mdy(&month.,1,&year.)) %to %sysfunc(intnx(month,%sysfunc(mdy(&month.,1,&year.)),0,e));
%if %sysfunc(putn(&day.,myholiday.)) %then %let i = %eval(&i. + 1);
%end;
&i.
%mend;
Something like:
data want; do i=intnx('month',today(),0,'beginning') to intnx('month',today(),0,'end'); if weekday(i) ne 1 then tot=sum(tot,1); end; run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.