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

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
anirudhs
Obsidian | Level 7
Thanks ... worked.

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
  • 3 replies
  • 951 views
  • 0 likes
  • 3 in conversation