# calculating business days in SPSS

9 messages
Open this post in threaded view
|

## calculating business days in SPSS

 Hi, I am trying to calculate the business days between 2 dates. The simple calculation below is actually not good enough because the difference is often less than 7 days: COMPUTE difference=CTIME.DAYS(date1-date2)*5/7. EXECUTE. I found some examples on this forum using 'loop', but those are not working when I try. Can someone help me? KR, Lara
Open this post in threaded view
|

## Re: calculating business days in SPSS

 Administrator "I found some examples on this forum using 'loop', but those are not working when I try. Can someone help me? " Errr, maybe you should  repost these and explain exactly what seems to be the problem? What exactly do you define as business days?   You mean Xmas and Easter? Thanksgiving? blah blah blah etc? Try again with an explicit definition of exactly what you are referring to. LaraVDB wrote Hi, I am trying to calculate the business days between 2 dates. The simple calculation below is actually not good enough because the difference is often less than 7 days: COMPUTE difference=CTIME.DAYS(date1-date2)*5/7. EXECUTE. I found some examples on this forum using 'loop', but those are not working when I try. Can someone help me? KR, Lara 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?"
Open this post in threaded view
|

## Re: calculating business days in SPSS

Open this post in threaded view
|

## Re: calculating business days in SPSS

 In reply to this post by David Marso So I want to calculate the business/working days between 2 dates (without taking into account holidays because the ones from Europe differ from those of America). When a weekend falls within the interval, those days should not be counted. When I try this (from another post): 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). SPSS gives an error 'End loop -> Incorrect variable name...' When I try this: LOOP #D=date1 TO date2 BY 86400. COMPUTE businessdays=SUM(businessdays,RANGE(XDATE.WKDAY(#D),2,6)). END LOOP. SPSS says 'LOOP -> incorrect variable name...' and 'END LOOP -> The End LOOP command does not follow an unclosed LOOP command...' Any idea what I did wrong? Thanks!
Open this post in threaded view
|

## Re: calculating business days in SPSS

 In reply to this post by Jon Peck Unfortunately this is also not working. Now it says: 'The formula references an undefined variable or could not be evaluated: 'NoneType' object has no attribute 'date' I'm using 2 date variables in the same format, so I have no idea what the problem might be...
Open this post in threaded view
|

## Re: calculating business days in SPSS

Open this post in threaded view
|

## Re: calculating business days in SPSS

 In reply to this post by LaraVDB The cause is most likely missing values in one of the date variables.  You would need to remove those cases or insert a substitute date in order for this to run successfully.  A date cannot be extracted from a system-missing value.On Wed, Feb 22, 2017 at 8:03 AM, LaraVDB wrote:Unfortunately this is also not working. Now it says: 'The formula references an undefined variable or could not be evaluated: 'NoneType' object has no attribute 'date' I'm using 2 date variables in the same format, so I have no idea what the problem might be... -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/calculating-business-days-in-SPSS-tp5733871p5733878.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD -- Jon K Peck[hidden email] ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD