Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate 'working days'

Status
Not open for further replies.

DrStephen

IS-IT--Management
Jul 8, 2003
33
US
[blue]I need to calculate 'working days' for clients. This is defined as the number of days between today() and an admission date -- excluding Saturdays and Sundays.

Does SAS have any kind of 'working day' function?
 
Sure they have the INTCK function. Why not just do simple subtraction.

data step;
set your_ds;
today = date();
days = today - sub_date; ***SUB_DATE IS YOUR SUBMISSION DATE IN SAS DATE FORMAT (N).;
run;

The var DAYS will be the number of days in the time span. It gets tricky if your date is before 1/1/1960. In that case use the function I mentioned.
Klaz2002
I hope this helps you.
 
[blue]I don't think INTCK will do it. INTCK will return the number of 'Day Intervals' between to dates. I can get the same value by substracting my two dates. Following an example from SAS, I tested the following:

d=intck'DAY',epiadmit,today));
w=intck('WEEK',epiadmit,today));
wdays = d-(w*2);

This purports to count only weekdays (i.e., knocks off two days for every week between the two dates). The problem is that it will substract two days for every week even if only one weekend day occured within the timespan. For example, Sunday (9/7/03) to Friday (9/12/03) returns 5 Days; Saturday (9/6/03) to Friday (9/12/03) returns 4 Days (even though the start date is one less. This must be because you don't get credit for a week until you hit both Saturday and Sunday.

It's still a useful function, but doesn't give me what I need (or, more specifically, doesn't give me what I need for a small percentage of the records).
 
How about using a Weekday function on AddmissionDate and see if it is 1,or 7 which is (Saturday or Sunday).. the code could be something like this.. I haven't tested the code though.....

data t;
set dsn.indst;
noofDays=intck('day',AdmissionDate,today());/**Get No. of Days**/
WorkingDays=0;
%macro wrkDay;
%do i=1 to NoOfDays;
if weekday(AdmissionDate) not in(1,7,.) then
WorkingDays=WorkingDays+1;
AdmissionDate=AdmissionDate+1;
%end;
%mend WrkDay;
%WrkDay;
run;
 
See if this is what you want:

data testdata;
input startdate date9. @11 enddate date9.;
format startdate enddate date9.;
datalines;
08jan2003 02feb2003
17jan2003 31aug2003
05dec2002 27mar2003
;

data workingdays;
set testdata;
days = enddate - startdate;
do i = 1 to days;
if weekday(startdate + i) in (1, 7) then days+(-1);
end;
drop i;
run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top