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