I am looking to calculate the number of days between 2 date variables. However, I need to calculate the business days (M-F) rather than calendar days. Does anyone have any ideas? Any help would be appreciated. V/r, Carleton Sea |
Simplest way is to use programmability.
Assuming that you have installed the Python Essentials and downloaded
the extendedTransforms.py module and the SPSSINC TRANS extension command
from the SPSS Community website (www.ibm.com/developerworks/spssdevcentral),
you could use this code.
Illustrated using the employee data.sav dataset shipped with Statistics. First create a second date variable a random number of days after birth date. select if ~missing(bdate). COMPUTE bdateplus=datesum(bdate, rv.poisson(10), "days"). format bdateplus(adate10). Now do the calculation. spssinc trans result=wkdays /formula "extendedTransforms.countWkdays(bdate, bdateplus)". This function assumes that week days are Mon-Fri. It has an optional parameter for other definitions. HTH, Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: "Sea, Carleton, VBAVACO" <[hidden email]> To: [hidden email] Date: 04/17/2012 08:10 AM Subject: [SPSSX-L] Calculating business days Sent by: "SPSSX(r) Discussion" <[hidden email]> I am looking to calculate the number of days between 2 date variables. However, I need to calculate the business days (M-F) rather than calendar days. Does anyone have any ideas? Any help would be appreciated. V/r,
Carleton Sea
|
Administrator
|
In reply to this post by Sea, Carleton, VBAVACO
Something like:
COMPUTE Days=CTIME.DAYS(date2-date1). *gives you number of days. COMPUTE Weeks=Days/7. *gives you number of weeks. COMPUTE Workdays=Weeks*5. --------------------------------- But there are holidays and leftovers, so this is approximate at best. COMPUTE Workdays=CTIME.DAYS(date2-date1)*5/7. *An exact evaluation would involve somewhat trickier code.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Sea, Carleton, VBAVACO
Let date1 and date2 be the two dates. Compute businessdays=0. Compute #tdate=date1. Set mxloops=100. /* make sure this number is greater than the date2-date1+1. Loop . + if (xdate.wkday(#tdate) ge 2 and xdate.wkday(date1) le 6) businessdays=businessdays+1. Compute #tdate=datesum(date1,1,"days"). End loop If (#tdate gt date2). Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sea, Carleton, VBAVACO I am looking to calculate the number of days between 2 date variables. However, I need to calculate the business days (M-F) rather than calendar days. Does anyone have any ideas? Any help would be appreciated. V/r, Carleton Sea |
Administrator
|
LOOP #D=date1 TO date2 BY 86400.
+ COMPUTE businessdays=SUM(businessdays,RANGE(XDATE.WKDAY(#D),2,6)). END LOOP. ;-))
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
Look Ma, no Python! ;-)
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Free forum by Nabble | Edit this page |