Help using Base SAS procedures

Counting the number of weekdays between 2 given dates

Accepted Solution Solved
Reply
Super Contributor
Posts: 266
Accepted Solution

Counting the number of weekdays between 2 given dates

My task is to find the percent of the school year a student was enrolled.  I need the number of weekdays that the student was enrolled in a particular school from their enterdate to their exitdate.  That number will be divided by 180 to get the percent_enrolled.  The school year starts on 8/1814 and ends on 6/4/15.

Sample data:

schoolid     studentID     enterdate          exitdate

3                    1           08/18/2014      06/04/2015

5                    2           08/18/2014     10/21/2015

5                    3           08/25/2014     10/07/2014

5                    3           01/05/2014     06/04/2015

7                    4           08/18/2014     10/01/2014

8                    4          10/02/2014      01/05/2015

7                    4          01/12/2015     06/04/2015

Student 1 is the easy case - the student enrolled on day 1 and stayed the entire school year, so his % enrollment is 180/180 = 100%

Student 2 entered on day 1 and unenrolled on Day 45.  His % enrollment would be 45/180=25% but note that there are actually more than 45 week days between day 1 and day 45 due to Labor Day being a holiday.  I'm assuming that some hard coding may have to be done to account for holidays that occur during weekdays.

Student 3 is presented to show there are multiple obs for some records.  This student left school = 5 on 10/07 but re-enrolled in the same school on 01/05.

Student 4 is presented here to show that students may have enrollments at more than one school.  So, this student will have a certain percentage attributed to school=7 and a separate percentage for school = 8.

     

Any help would be greatly appreciated since this is a little above my pay grade.

Gregg


Accepted Solutions
Solution
‎03-20-2015 11:33 AM
Super User
Super User
Posts: 7,392

Re: Counting the number of weekdays between 2 given dates

Hi,

A combination of intck:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

And this post (there are many others here on dates/holidays):

View solution in original post


All Replies
Super User
Posts: 9,662

Re: Counting the number of weekdays between 2 given dates

I think you have some typo .

schoolid     studentID     enterdate          exitdate

3                    1           08/18/2014      06/04/2015   <--- the number of weekdays should be 209

5                    2           08/18/2014     10/21/2015 <----2014   <--- the number of weekdays should be 47

5                    3           08/25/2014     10/07/2014

5                    3           01/05/2014 <--2015    06/04/2015

7                    4           08/18/2014     10/01/2014

8                    4          10/02/2014      01/05/2015

7                    4          01/12/2015     06/04/2015

Super Contributor
Posts: 266

Re: Counting the number of weekdays between 2 given dates

The number would be 209 if there were no holidays.  This is why I mentioned that I may have to hard code some of the data step.  Thanksgiving, Fall Break, Winter Break, etc cannot be counted even though some of those days are weekdays.

Solution
‎03-20-2015 11:33 AM
Super User
Super User
Posts: 7,392

Re: Counting the number of weekdays between 2 given dates

Hi,

A combination of intck:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

And this post (there are many others here on dates/holidays):

Super Contributor
Posts: 266

Re: Counting the number of weekdays between 2 given dates

This is very helpful.  One thing though: the notes regarding this code indicate that Sunday is counted as a weekday.  Is that correct?  I only want to count Mon - Fri.

wdvar=intck('weekday7w','01jan97'd,

  '01feb97'd);

put wdvar;

Super User
Posts: 9,662

Re: Counting the number of weekdays between 2 given dates

data _null_;

wdvar=intck('weekday17w','08mar2015'd,

  '10mar2015'd);

put wdvar;

run;

Super User
Posts: 17,750

Re: Counting the number of weekdays between 2 given dates

According to SAS functions, M-F is a weekday.

Super Contributor
Posts: 266

Re: Counting the number of weekdays between 2 given dates

I had time to explore the links you provided.  I am now on track. Thanks for answering this question.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 301 views
  • 0 likes
  • 4 in conversation