Identifying a particular date in the future

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Identifying a particular date in the future

Tamra Boyce
I am working on a school attendance outcome evaluation. I am trying to
figure out how to write syntax that will return the date that will occur
at a future time. I have calculated the attendance that occurs pre-
intervention. Then the intervention occurs.  Next is the post-intervention
period.  At the end of the 90-day post intevention starts the second
intervention period.  I need to have syntax that returns the month, day
and year that marks the end of the post-intervention period because that
particluar day will start the secondary intervention period.  I appreciate
any syntax help.

Thanks

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Identifying a particular date in the future

Maguin, Eugene
Tamara,

As I understand it, you have a known date for the pretest or the
intervention. Let that be called predate. You need a second date 90 days
ahead, call it postdate. Then,

Compute postdate=predate+90*24*3600.
Format postdate(adate10).

The important thing to understand is that spss stores dates as the number of
seconds since the switchover date to the Gregorian calender. The syntax
reference probably has a better explanation of all this but that's the
basics. Anyway, the syntax above just adds 90 days worth of seconds to the
existing date.

Let me also add that spss has added some new date functions that may make
the compuation simpler.

Gene Maguin

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Identifying a particular date in the future

Mwenza Blell
In reply to this post by Tamra Boyce
Hi,
If I have understood the question correctly you should be able to compute the
end of intervention one (t2 which is 90 days after t1) assuming you have the
variable representing the start of intervention one (t1) in date format (in my
version of SPSS this is available in variable view, type is the second column,
one of the types available is date in various formats). Assuming that is taken
care of you can use the compute function to compute t2
[Transform > Date Arithmetic (in the Function Group box) >
Datesum(2) (in the Function box)].

The explanation of this function says:

"DATESUM(datetime, value, "unit", "method"). Numeric. Calculates a date or time
value a specified number of units from a given date or time value, where
datetime is a date or time format variable (or numeric value that represents a
valid date/time value), and "unit" is one of the following string literal
values, enclosed in quotes: years, quarters, months, weeks, days, hours,
minutes, seconds.  The optional method, enclosed in quotes, can be "rollover" or
"closest". The rollover method advances excess days into the next month. The
closest method uses the closest legitimate date within the the month; this is
the default.

The value returned is a date/time value expressed as a number of seconds. To
display the value as a date/time, assign the appropriate format to the variable."

Click the up arrow and the expression will read DATESUM(?,?,?,?)
and as indicated in the description above the first ? should be replaced by your
t1 variable, the second ? should be replaced by the number 90, the third ?
should be replaced by "days", and the fourth ? should be replaced by "rollover".

You can of course use the same syntax to figure out the end date for
intervention 2 once you get the end date for intervention 1 by just replacing
the t1 variable with the t2 variable you just created.

Hope that helps (and I understood the question properly).

Apologies if I wasn't meant to reply to the whole list.

Best,
Mwenza

Quoting Tamra Boyce <[hidden email]>:

> I am working on a school attendance outcome evaluation. I am trying to
> figure out how to write syntax that will return the date that will occur
> at a future time. I have calculated the attendance that occurs pre-
> intervention. Then the intervention occurs.  Next is the post-intervention
> period.  At the end of the 90-day post intevention starts the second
> intervention period.  I need to have syntax that returns the month, day
> and year that marks the end of the post-intervention period because that
> particluar day will start the secondary intervention period.  I appreciate
> any syntax help.
>
> Thanks
>
> =====================
> 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
>
>

=====================
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
Reply | Threaded
Open this post in threaded view
|

ERROR 550

Albert-Jan Roskam
Hi list,

The code below worked last Friday, but now it consistently yields an error 550. Any idea what causes this? It works without the DATASET commands, but why not with them? The size of the data set is about 160k records; 147 vars.

Thanks in advance!

Cheers!
Albert-Jan

get file = 'out_dir/matched_TOTAL.sav'.
dataset name mysource.
dataset copy mydoubles.
dataset activate mydoubles.
aggregate outfile = * mode = addvariables / break = case_orig / count = n.


>Error # 550
>An SPSS program error has occurred: A procedure has attempted to add more
>variables to the file than it provided for in its call to OBINIT.  The
>error was detected in a call to OBPINI.  Please note the circumstances
>under which this error occurred, attempting to replicate it if possible,
>and then notify SPSS Technical Support.
>This command not executed.



>Warning # 552
>Possibly due to another error, a procedure has defined more new variables
>than it has added to the file.  All those which have been defined but not
>added will be discarded and will be unavailable for further processing.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Follow Up to identifying future date

Tamra Boyce
In reply to this post by Mwenza Blell
Thanks to  Mwenza and Gene for your responses - it helped get me alot.  Now, however, I have a more complicated syntax question (complicated for me
that is)  with the same data set.

I have created a range of time between the Program Intervention End Date (Time1) and Post Program Intervention Period (Time2)  that subtracted all
school recognized holidays and weekends returning numbers anywhere from 10 days to 147 of possible enrollment days.

I want to know what date (day, month and year) (Time3)  the possible enrollment day would fall on.  Is it possible to write syntax to do this?

For Example

ID    Time1       Time2             DateDiff    DateDiff-HolWknd  Time3
253   1/27/2008   6/11/2008   136         86                ?
345   2/16/2008   6/11/2008   116         72                ?

Thanks all for your help.

Tamra Boyce
Principal Analyst
Hennepin County
300 South 6th Street
Minneapolis, MN 55487
PH:(612) 348-7059






             Mwenza Blell <[hidden email]>
             Sent by: "SPSSX(r) Discussion"
             <[hidden email]>                                                                                                            To
                                                                     [hidden email]
                                                                                                                                                   cc
             06/23/2008 09:04 AM
                                                                                                                                              Subject
                                                                     Re: Identifying a particular date in the future
                            Please respond to
                         [hidden email]








Hi,
If I have understood the question correctly you should be able to compute the
end of intervention one (t2 which is 90 days after t1) assuming you have the
variable representing the start of intervention one (t1) in date format (in my
version of SPSS this is available in variable view, type is the second column,
one of the types available is date in various formats). Assuming that is taken
care of you can use the compute function to compute t2
[Transform > Date Arithmetic (in the Function Group box) >
Datesum(2) (in the Function box)].

The explanation of this function says:

"DATESUM(datetime, value, "unit", "method"). Numeric. Calculates a date or time
value a specified number of units from a given date or time value, where
datetime is a date or time format variable (or numeric value that represents a
valid date/time value), and "unit" is one of the following string literal
values, enclosed in quotes: years, quarters, months, weeks, days, hours,
minutes, seconds.  The optional method, enclosed in quotes, can be "rollover" or
"closest". The rollover method advances excess days into the next month. The
closest method uses the closest legitimate date within the the month; this is
the default.

The value returned is a date/time value expressed as a number of seconds. To
display the value as a date/time, assign the appropriate format to the variable."

Click the up arrow and the expression will read DATESUM(?,?,?,?)
and as indicated in the description above the first ? should be replaced by your
t1 variable, the second ? should be replaced by the number 90, the third ?
should be replaced by "days", and the fourth ? should be replaced by "rollover".

You can of course use the same syntax to figure out the end date for
intervention 2 once you get the end date for intervention 1 by just replacing
the t1 variable with the t2 variable you just created.

Hope that helps (and I understood the question properly).

Apologies if I wasn't meant to reply to the whole list.

Best,
Mwenza

Quoting Tamra Boyce <[hidden email]>:

> I am working on a school attendance outcome evaluation. I am trying to
> figure out how to write syntax that will return the date that will occur
> at a future time. I have calculated the attendance that occurs pre-
> intervention. Then the intervention occurs.  Next is the post-intervention
> period.  At the end of the 90-day post intevention starts the second
> intervention period.  I need to have syntax that returns the month, day
> and year that marks the end of the post-intervention period because that
> particluar day will start the secondary intervention period.  I appreciate
> any syntax help.
>
> Thanks
>
> =====================
> 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
>
>

=====================
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


Disclaimer: Information in this message or an attachment may be government data and thereby subject to the Minnesota Government Data Practices Act, Minnesota Statutes, Chapter 13, may be subject to attorney-client or work product privilege, may be confidential, privileged, proprietary, or otherwise protected, and the unauthorized review, copying, retransmission, or other use or disclosure of the information is strictly prohibited. If you are not the intended recipient of this message, please immediately notify the sender of the transmission error and then promptly delete this message from your computer system.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Follow Up to identifying future date

Maguin, Eugene
Tamara,

>>>I have created a range of time between the Program Intervention End Date
(Time1) and Post Program Intervention Period (Time2)  that subtracted all
school recognized holidays and weekends returning numbers anywhere from 10
days to 147 of possible enrollment days.

I want to know what date (day, month and year) (Time3)  the possible
enrollment day would fall on.  Is it possible to write syntax to do this?

For Example

ID    Time1       Time2       DateDiff    DateDiff-HolWknd  Time3
253   1/27/2008   6/11/2008   136         86                ?
345   2/16/2008   6/11/2008   116         72                ?


Tell me if I understand what you want. Taking id=253 as an example, you
found that the difference between T1 and T2 was 136 days. Are you saying
that between 1/27 and 6/11 there were 50 weekend days and holidays, leaving
a total of 86 days? If all that is so, what then is T3 supposed to be? Given
the T2 date, what is the rule for computing T3? That is missing.

Gene Maguin

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Follow Up to identifying future date

Maguin, Eugene
In reply to this post by Tamra Boyce
All,

Tamara replied to me off-list. Here is her reply.

Gene, you understood exactly.  Once I partialled out the holidays and
weekends, there were only 86 days where a child could attend school. I
forgot a
piece so thanks for the opportunity to clarify because this thing is giving
me a headache and maybe my clarification can help simplify the request.
As you can tell, I'm really struggling with logically outlining what I want.

Let's make Time3 - the date at which the Child 253 would have completed 30
enrollment days between Time1 and Time2 subtracting all holidays and
weekends.

So, I need:  at enrollment day 30, what would be the date (monday, day and
year)?  Is this possible?

For Example

ID    Time1       Time2       DateDiff    DateDiff-HolWknd  Time3
253   1/27/2008   6/11/2008   136         86                ?
345   2/16/2008   6/11/2008   116         72                ?


Tamara,

This is one way to do this. There are probably others. It does what you'd do
by hand. That is, you'd get out the calender, mark in school holidays and,
starting at the T1 date, count forward 30 days, skipping over weekends and
holidays as you went. Basically, that is what spss will have to do. The
problem is the code.
Let time1 by the time 1 date.

I think what I'd do is the following. Get the min and max values of time1
and for that range of values make a list of every weekend and holiday date.
Suppose there are 10 such dates. Call them hwk1 to hwk10. Do a series of
computes to get them into the file.

Compute hwk1=date.mdy(2,2,2008).
Etc.
Compute hwk10=date.mdy(3,2,2008).

*  define a vector.
Vector hwk=hwk1 to hwk10.
*  loop through the vector to identify holidays and weekends and
*  increment time3.
Compute time3=time1.
Compute time3=DATESUM(time1,#i,"days","closest").
Loop #i=1 to 10.
If (time1 le hwk(#i) and hwk(#i) le time3)
time3=DATESUM(time3,1,"days","closest").
End loop.
Execute.


I haven't tested this but I think it will work. Let me know if you have
trouble. Post the output from the log item so that we can see the syntax and
the error statement(s).

Gene Maguin

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Identifying a particular date in the future

Richard Ristow
In reply to this post by Maguin, Eugene
A comment on coding technique. At 09:36 AM 6/23/2008, Gene Maguin wrote:

>Let [the initial date] be called predate. You need a second date 90
>days ahead, call it postdate. Then,
>
>Compute postdate=predate+90*24*3600.
>Format postdate(adate10).
>
>The important thing to understand is that spss stores dates as the
>number of seconds since the switchover date to the Gregorian calender.

The code posted is correct. However, I think that code that doesn't
explicitly depend on the date-time representation is clearer.  The
equivalent alternative code is,

Compute postdate=predate+TIME.DAYS(90).
Format postdate(adate10).

This also avoids misunderstanding about which quantities are 'magic
numbers' ("24" and "3600"), and which relate to the problem at hand ("90").

By the way, see also TIME.HMS, which is astonishingly versatile -- it
will give, for example, correct results for TIME.HMS(1,15,25), for
TIME.HMS(1), TIME.HMS(1.5), and for TIME.HMS(0,90),

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Follow Up to identifying future date

Richard Ristow
In reply to this post by Maguin, Eugene
At 04:06 PM 6/23/2008, Gene Maguin wrote, responding to Tamra Boyce :

>>Let's make Time3 - the date at which the Child 253 would have
>>completed 30 enrollment days between Time1 and Time2 subtracting
>>all holidays and weekends. At enrollment day 30, what would be the
>>date (month, day and year)?
>>
>>For Example
>>
>>ID    Time1       Time2       DateDiff    DateDiff-HolWknd  Time3
>>253   1/27/2008   6/11/2008   136         86                ?
>>345   2/16/2008   6/11/2008   116         72                ?
>
>This does what you'd do by hand: mark school holidays and, starting
>at the T1 date, count forward 30 days, skipping over weekends and
>holidays as you went.
>
>Get the min and max values of time1 and for that range of values
>make a list of every weekend and holiday date.

Yes, but you don't need to make a list of weekend dates. Using
function XDATE.WKDAY will be much easier.

>*  define a vector.
>Vector hwk=hwk1 to hwk10.
>*  loop through the vector to identify holidays and weekends and .
>*  increment time3.                                              .
>Compute time3=time1.
>Loop #i=1 to 10.
>.  If (time1 le hwk(#i) and hwk(#i) le time3)
>        time3=DATESUM(time3,1,"days","closest").
>End loop.

This doesn't work for me. Recalling that 'time3' is initialized to
the value of 'time1', the 'If' within the loop will never be
satisfied, and 'time3' will never be incremented, unless one of the
marked dates ('hwkNN') falls exactly on 'time1'.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Follow Up to identifying future date

Richard Ristow
In reply to this post by Maguin, Eugene
Some time on or before 6/23/2008, Tamra Boyce wrote Gene Maguin, off-list:

>>Gene, you understood exactly.  Once I partialled out the holidays
>>and weekends, there were only 86 days where a child could attend school.
>>
>>Let's make Time3 - the date at which the Child 253 would have
>>completed 30 enrollment days between Time1 and Time2 subtracting
>>all holidays and weekends.
>>
>>So, I need:  at enrollment day 30, what would be the date (month, day and
>>year)? For example,
>>
>>ID    Time1       Time2       DateDiff    DateDiff-HolWknd  Time3
>>253   1/27/2008   6/11/2008   136         86                ?
>>345   2/16/2008   6/11/2008   116         72                ?

Gene responded,
>By hand, you'd get out the calender, mark in school holidays and,
>starting at the T1 date, count forward 30 days, skipping over
>weekends and holidays as you went.

Yes, exactly like that:

The following logic loops through days, taking advantage of the
XDATE.WKDAY function. Since it checks every day in the range, it's
probably not very efficient; but it should work.

I've changed variable names. And because I don't have the list of
holidays for Tamra's test data, here's a different test dataset:
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 01:06:54       |
|-----------------------------|---------------------------|
[TestData]

   ID      Time1      Time2

  253 01/28/2008 02/25/2008
  345 02/06/2008 04/16/2008

Number of cases read:  2    Number of cases listed:  2

DATASET COPY     LoopDays  WINDOW=FRONT.
DATASET ACTIVATE LoopDays  WINDOW=Front.

NUMERIC DaysAbs  DaysSchl (F4).
COMPUTE DaysAbs  = CTIME.DAYS(Time2-Time1).

NUMERIC Dy30Abs  Dy30Schl (ADATE10).
COMPUTE Dy30Abs  = Time1 + TIME.DAYS(30).

DO IF   $CASENUM EQ 1.
*  Holidays observed:                            .
.  COMPUTE  #Holdy01  = DATE.MDY(02,02,2008) /* Groundhog Day    */.
.  COMPUTE  #Holdy02  = DATE.MDY(02,14,2008) /* Valentine's Day  */.
.  COMPUTE  #Holdy03  = DATE.MDY(03,15,2008) /* Ides of March    */.
.  COMPUTE  #Holdy04  = DATE.MDY(04,01,2008) /* April Fools' Day */.
.  COMPUTE  #Holdy05  = DATE.MDY(04,15,2008) /* IRS Day          */.
END IF.
FORMATS     #Holdy01 TO #Holdy05 (ADATE10).

NUMERIC DaysAbs  DaysSchl (F4).
COMPUTE DaysAbs  = CTIME.DAYS(Time2-Time1).

NUMERIC #Day      (ADATE10).
NUMERIC #SchlDys  (F4).
COMPUTE #SchlDys = 0.

LOOP    #Day = time1 TO time2 BY TIME.DAYS(1).
.  DO IF   ANY(XDATE.WKDAY(#Day),7,1)   /* Weekend days */.
.  ELSE IF ANY(#Day,
                #Holdy01,#Holdy02,#Holdy03,
                #Holdy04,#Holdy05)       /* Holidays     */.
.  ELSE.
.     COMPUTE #SchlDys = #SchlDys + 1.
.     IF      MISSING(Dy30Schl)
          AND  #SchlDys GE 30
                       Dy30Schl = #Day.
.  END IF.
END LOOP.
COMPUTE DaysSchl = #SchlDys.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 01:15:08       |
|-----------------------------|---------------------------|
[LoopDays]

   ID      Time1      Time2 DaysAbs DaysSchl    Dy30Abs   Dy30Schl

  253 01/28/2008 03/10/2008     42      30   02/27/2008 03/10/2008
  345 02/06/2008 04/16/2008     70      48   03/07/2008 03/19/2008

Number of cases read:  2    Number of cases listed:  2
=============================
APPENDIX: Test data, and code
=============================

DATA LIST LIST
   /ID   Time1       Time2
   (F4,  ADATE10,    ADATE10).
BEGIN DATA
   253   01/28/2008  03/10/2008
   345   02/06/2008  04/16/2008
END DATA.

DATASET NAME     TestData   WINDOW=FRONT.
LIST.


*==================================.
*  Gene Maguin's logic:            .
*  ............................... .
DATASET ACTIVATE TestData   WINDOW=FRONT.
DATASET COPY     Maguin     WINDOW=FRONT.
DATASET ACTIVATE Maguin     WINDOW=FRONT.
*  Dates not to be counted as "school days":     .

*     Weekends:                                  .
COMPUTE  Hwk01  = DATE.MDY(02,02,2008)   /* Sat */.
COMPUTE  Hwk02  = DATE.MDY(02,03,2008)   /* Sun */.
COMPUTE  Hwk03  = DATE.MDY(02,09,2008)   /* Sat */.
COMPUTE  Hwk04  = DATE.MDY(02,10,2008)   /* Sun */.
COMPUTE  Hwk05  = DATE.MDY(02,16,2008).
COMPUTE  Hwk06  = DATE.MDY(02,17,2008).
COMPUTE  Hwk07  = DATE.MDY(02,23,2008).
COMPUTE  Hwk08  = DATE.MDY(02,24,2008).
COMPUTE  Hwk09  = DATE.MDY(03,01,2008).
COMPUTE  Hwk10  = DATE.MDY(03,02,2008).
COMPUTE  Hwk11  = DATE.MDY(03,08,2008).
COMPUTE  Hwk12  = DATE.MDY(03,09,2008).
COMPUTE  Hwk13  = DATE.MDY(03,15,2008).
COMPUTE  Hwk14  = DATE.MDY(03,16,2008).
COMPUTE  Hwk15  = DATE.MDY(03,22,2008).
COMPUTE  Hwk16  = DATE.MDY(03,23,2008).
COMPUTE  Hwk17  = DATE.MDY(03,29,2008).
COMPUTE  Hwk18  = DATE.MDY(03,30,2008).
COMPUTE  Hwk19  = DATE.MDY(04,05,2008).
COMPUTE  Hwk20  = DATE.MDY(04,06,2008).
COMPUTE  Hwk21  = DATE.MDY(04,12,2008).
COMPUTE  Hwk22  = DATE.MDY(04,13,2008).
COMPUTE  Hwk23  = DATE.MDY(04,19,2008).
COMPUTE  Hwk24  = DATE.MDY(04,20,2008).
COMPUTE  Hwk25  = DATE.MDY(04,26,2008).
COMPUTE  Hwk26  = DATE.MDY(04,27,2008).
*  Holidays observed:                            .
COMPUTE  Hwk27  = DATE.MDY(02,02,2008) /* Groundhog Day    */.
COMPUTE  Hwk28  = DATE.MDY(02,14,2008) /* Valentine's Day  */.
COMPUTE  Hwk29  = DATE.MDY(03,15,2008) /* Ides of March    */.
COMPUTE  Hwk30  = DATE.MDY(04,01,2008) /* April Fools' Day */.
COMPUTE  Hwk31  = DATE.MDY(04,15,2008) /* IRS Day          */.

FORMATS  Hwk01 TO Hwk31   (ADATE10).

*  define a vector.
Vector hwk=hwk01 to hwk31.
*  loop through the vector to identify holidays and weekends and .
*  increment time3 (now "time3").                             .
Compute time3=time1.
Loop #i=1 to 26.
.  If (time1 le hwk(#i) and hwk(#i) le time3)
    time3=DATESUM(time3,1,"days","closest").
.  FORMATS #i (F3).
.  /**/ PRINT / 'Pass ' #i ': Latest end date=' time3.
End loop.

LIST ID TO time3.


*==================================.
*  Revised logic, by W.R. Ristow:  .
*  ............................... .

DATASET ACTIVATE TestData  WINDOW=FRONT.
DATASET COPY     LoopDays  WINDOW=FRONT.
DATASET ACTIVATE LoopDays  WINDOW=Front.

NUMERIC DaysAbs  DaysSchl (F4).
COMPUTE DaysAbs  = CTIME.DAYS(Time2-Time1).

NUMERIC Dy30Abs  Dy30Schl (ADATE10).
COMPUTE Dy30Abs  = Time1 + TIME.DAYS(30).

DO IF   $CASENUM EQ 1.
*  Holidays observed:                            .
.  COMPUTE  #Holdy01  = DATE.MDY(02,02,2008) /* Groundhog Day    */.
.  COMPUTE  #Holdy02  = DATE.MDY(02,14,2008) /* Valentine's Day  */.
.  COMPUTE  #Holdy03  = DATE.MDY(03,15,2008) /* Ides of March    */.
.  COMPUTE  #Holdy04  = DATE.MDY(04,01,2008) /* April Fools' Day */.
.  COMPUTE  #Holdy05  = DATE.MDY(04,15,2008) /* IRS Day          */.
END IF.
FORMATS     #Holdy01 TO #Holdy05 (ADATE10).


NUMERIC #Day      (ADATE10).
NUMERIC #SchlDys  (F4).
COMPUTE #SchlDys = 0.

LOOP    #Day = time1 TO time2 BY TIME.DAYS(1).
.  DO IF   ANY(XDATE.WKDAY(#Day),7,1)   /* Weekend days */.
.  ELSE IF ANY(#Day,
                #Holdy01,#Holdy02,#Holdy03,
                #Holdy04,#Holdy05)       /* Holidays     */.
.  ELSE.
.     COMPUTE #SchlDys = #SchlDys + 1.
.     IF      MISSING(Dy30Schl)
          AND  #SchlDys GE 30
                       Dy30Schl = #Day.
.  END IF.
END LOOP.
COMPUTE DaysSchl = #SchlDys.

LIST.

=====================
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
Reply | Threaded
Open this post in threaded view
|

VARSTOCASES

Thomas, Dave-2
In reply to this post by Richard Ristow
Need help on this one:

Original file:

ID      Var1    Var2 Var3
1       2       4       5
2       3       4       5
3       1       2       2


Need to create:

ID      dep1    dep2    dep3
1       2       .       .
1       .       4       .
1       .       .       5
2       3       .       .
2       .       4       .
2       .       .       5
3       1       .       .
3       .       2       .
3       .       .       2

Any ideas?

Thanks in advance....

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: VARSTOCASES

Richard Ristow
At 10:30 AM 6/24/2008, Thomas, Dave wrote:

>Original file:
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 13:38:09       |
|-----------------------------|---------------------------|
ID Var1 Var2 Var3

  1   2    4    5
  2   3    4    5
  3   1    2    2

Number of cases read:  3    Number of cases listed:  3

>Need to create:
>
>ID      dep1    dep2    dep3
>1       2       .       .
>1       .       4       .
>1       .       .       5
>2       3       .       .
[...]
Here goes. Delete variables "Datum#" and "VarX" later, if you want
to; but I wouldn't delete "Datum#", as then you'd have records
without unique keys.

VARSTOCASES
    /MAKE VarX FROM Var1 Var2 Var3
    /INDEX = Datum# "X; datum whose value is given"(3)
    /KEEP  = ID
    /NULL  = KEEP.


Variables to Cases
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 15:22:01       |
|-----------------------------|---------------------------|
Generated Variables
|------|---------------|
|Name  |Label          |
|------|---------------|
|Datum#|X; datum whose |
|      |value is given |
|------|---------------|
|VarX  |<none>         |
|------|---------------|

Processing Statistics
|-------------|-|
|Variables In |4|
|Variables Out|3|
|-------------|-|

VECTOR  dep(3,F2).
COMPUTE dep(Datum#) = VarX.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 15:23:54       |
|-----------------------------|---------------------------|
ID Datum# VarX dep1 dep2 dep3

  1     1    2    2    .    .
  1     2    4    .    4    .
  1     3    5    .    .    5
  2     1    3    3    .    .
  2     2    4    .    4    .
  2     3    5    .    .    5
  3     1    1    1    .    .
  3     2    2    .    2    .
  3     3    2    .    .    2

Number of cases read:  9    Number of cases listed:  9
=============================
APPENDIX: Test data, and code
=============================
DATA LIST LIST/
       ID      Var1    Var2 Var3
       (4F2).
BEGIN DATA
       1       2       4       5
       2       3       4       5
       3       1       2       2
END DATA.
LIST.

VARSTOCASES
    /MAKE VarX FROM Var1 Var2 Var3
    /INDEX = Datum# "X; datum whose value is given"(3)
    /KEEP  = ID
    /NULL  = KEEP.

VECTOR  dep(3,F2).
COMPUTE dep(Datum#) = VarX.

LIST.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Follow Up to identifying future date

Tamra Boyce
In reply to this post by Richard Ristow
This worked absolutely perfectly. You guys have no idea how much this has helped me move this project along.  Many many thanks.  I appreciate the time
you took to work this out.

Thanks again.


Tamra Boyce
Principal Analyst
Hennepin County
Research, Planning and Development
300 South 6th Street
Minneapolis, MN 55487
PH:(612) 348-7059






             Richard Ristow <[hidden email]>
             Sent by: "SPSSX(r) Discussion"
             <[hidden email]>                                                                                                            To
                                                                     [hidden email]
                                                                                                                                                   cc
             06/24/2008 12:23 AM
                                                                                                                                              Subject
                                                                     Re: Follow Up to identifying future date
                            Please respond to
                Richard Ristow <[hidden email]>








Some time on or before 6/23/2008, Tamra Boyce wrote Gene Maguin, off-list:

>>Gene, you understood exactly.  Once I partialled out the holidays
>>and weekends, there were only 86 days where a child could attend school.
>>
>>Let's make Time3 - the date at which the Child 253 would have
>>completed 30 enrollment days between Time1 and Time2 subtracting
>>all holidays and weekends.
>>
>>So, I need:  at enrollment day 30, what would be the date (month, day and
>>year)? For example,
>>
>>ID    Time1       Time2       DateDiff    DateDiff-HolWknd  Time3
>>253   1/27/2008   6/11/2008   136         86                ?
>>345   2/16/2008   6/11/2008   116         72                ?

Gene responded,
>By hand, you'd get out the calender, mark in school holidays and,
>starting at the T1 date, count forward 30 days, skipping over
>weekends and holidays as you went.

Yes, exactly like that:

The following logic loops through days, taking advantage of the
XDATE.WKDAY function. Since it checks every day in the range, it's
probably not very efficient; but it should work.

I've changed variable names. And because I don't have the list of
holidays for Tamra's test data, here's a different test dataset:
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 01:06:54       |
|-----------------------------|---------------------------|
[TestData]

   ID      Time1      Time2

  253 01/28/2008 02/25/2008
  345 02/06/2008 04/16/2008

Number of cases read:  2    Number of cases listed:  2

DATASET COPY     LoopDays  WINDOW=FRONT.
DATASET ACTIVATE LoopDays  WINDOW=Front.

NUMERIC DaysAbs  DaysSchl (F4).
COMPUTE DaysAbs  = CTIME.DAYS(Time2-Time1).

NUMERIC Dy30Abs  Dy30Schl (ADATE10).
COMPUTE Dy30Abs  = Time1 + TIME.DAYS(30).

DO IF   $CASENUM EQ 1.
*  Holidays observed:                            .
.  COMPUTE  #Holdy01  = DATE.MDY(02,02,2008) /* Groundhog Day    */.
.  COMPUTE  #Holdy02  = DATE.MDY(02,14,2008) /* Valentine's Day  */.
.  COMPUTE  #Holdy03  = DATE.MDY(03,15,2008) /* Ides of March    */.
.  COMPUTE  #Holdy04  = DATE.MDY(04,01,2008) /* April Fools' Day */.
.  COMPUTE  #Holdy05  = DATE.MDY(04,15,2008) /* IRS Day          */.
END IF.
FORMATS     #Holdy01 TO #Holdy05 (ADATE10).

NUMERIC DaysAbs  DaysSchl (F4).
COMPUTE DaysAbs  = CTIME.DAYS(Time2-Time1).

NUMERIC #Day      (ADATE10).
NUMERIC #SchlDys  (F4).
COMPUTE #SchlDys = 0.

LOOP    #Day = time1 TO time2 BY TIME.DAYS(1).
.  DO IF   ANY(XDATE.WKDAY(#Day),7,1)   /* Weekend days */.
.  ELSE IF ANY(#Day,
                #Holdy01,#Holdy02,#Holdy03,
                #Holdy04,#Holdy05)       /* Holidays     */.
.  ELSE.
.     COMPUTE #SchlDys = #SchlDys + 1.
.     IF      MISSING(Dy30Schl)
          AND  #SchlDys GE 30
                       Dy30Schl = #Day.
.  END IF.
END LOOP.
COMPUTE DaysSchl = #SchlDys.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |24-JUN-2008 01:15:08       |
|-----------------------------|---------------------------|
[LoopDays]

   ID      Time1      Time2 DaysAbs DaysSchl    Dy30Abs   Dy30Schl

  253 01/28/2008 03/10/2008     42      30   02/27/2008 03/10/2008
  345 02/06/2008 04/16/2008     70      48   03/07/2008 03/19/2008

Number of cases read:  2    Number of cases listed:  2
=============================
APPENDIX: Test data, and code
=============================

DATA LIST LIST
   /ID   Time1       Time2
   (F4,  ADATE10,    ADATE10).
BEGIN DATA
   253   01/28/2008  03/10/2008
   345   02/06/2008  04/16/2008
END DATA.

DATASET NAME     TestData   WINDOW=FRONT.
LIST.


*==================================.
*  Gene Maguin's logic:            .
*  ............................... .
DATASET ACTIVATE TestData   WINDOW=FRONT.
DATASET COPY     Maguin     WINDOW=FRONT.
DATASET ACTIVATE Maguin     WINDOW=FRONT.
*  Dates not to be counted as "school days":     .

*     Weekends:                                  .
COMPUTE  Hwk01  = DATE.MDY(02,02,2008)   /* Sat */.
COMPUTE  Hwk02  = DATE.MDY(02,03,2008)   /* Sun */.
COMPUTE  Hwk03  = DATE.MDY(02,09,2008)   /* Sat */.
COMPUTE  Hwk04  = DATE.MDY(02,10,2008)   /* Sun */.
COMPUTE  Hwk05  = DATE.MDY(02,16,2008).
COMPUTE  Hwk06  = DATE.MDY(02,17,2008).
COMPUTE  Hwk07  = DATE.MDY(02,23,2008).
COMPUTE  Hwk08  = DATE.MDY(02,24,2008).
COMPUTE  Hwk09  = DATE.MDY(03,01,2008).
COMPUTE  Hwk10  = DATE.MDY(03,02,2008).
COMPUTE  Hwk11  = DATE.MDY(03,08,2008).
COMPUTE  Hwk12  = DATE.MDY(03,09,2008).
COMPUTE  Hwk13  = DATE.MDY(03,15,2008).
COMPUTE  Hwk14  = DATE.MDY(03,16,2008).
COMPUTE  Hwk15  = DATE.MDY(03,22,2008).
COMPUTE  Hwk16  = DATE.MDY(03,23,2008).
COMPUTE  Hwk17  = DATE.MDY(03,29,2008).
COMPUTE  Hwk18  = DATE.MDY(03,30,2008).
COMPUTE  Hwk19  = DATE.MDY(04,05,2008).
COMPUTE  Hwk20  = DATE.MDY(04,06,2008).
COMPUTE  Hwk21  = DATE.MDY(04,12,2008).
COMPUTE  Hwk22  = DATE.MDY(04,13,2008).
COMPUTE  Hwk23  = DATE.MDY(04,19,2008).
COMPUTE  Hwk24  = DATE.MDY(04,20,2008).
COMPUTE  Hwk25  = DATE.MDY(04,26,2008).
COMPUTE  Hwk26  = DATE.MDY(04,27,2008).
*  Holidays observed:                            .
COMPUTE  Hwk27  = DATE.MDY(02,02,2008) /* Groundhog Day    */.
COMPUTE  Hwk28  = DATE.MDY(02,14,2008) /* Valentine's Day  */.
COMPUTE  Hwk29  = DATE.MDY(03,15,2008) /* Ides of March    */.
COMPUTE  Hwk30  = DATE.MDY(04,01,2008) /* April Fools' Day */.
COMPUTE  Hwk31  = DATE.MDY(04,15,2008) /* IRS Day          */.

FORMATS  Hwk01 TO Hwk31   (ADATE10).

*  define a vector.
Vector hwk=hwk01 to hwk31.
*  loop through the vector to identify holidays and weekends and .
*  increment time3 (now "time3").                             .
Compute time3=time1.
Loop #i=1 to 26.
.  If (time1 le hwk(#i) and hwk(#i) le time3)
    time3=DATESUM(time3,1,"days","closest").
.  FORMATS #i (F3).
.  /**/ PRINT / 'Pass ' #i ': Latest end date=' time3.
End loop.

LIST ID TO time3.


*==================================.
*  Revised logic, by W.R. Ristow:  .
*  ............................... .

DATASET ACTIVATE TestData  WINDOW=FRONT.
DATASET COPY     LoopDays  WINDOW=FRONT.
DATASET ACTIVATE LoopDays  WINDOW=Front.

NUMERIC DaysAbs  DaysSchl (F4).
COMPUTE DaysAbs  = CTIME.DAYS(Time2-Time1).

NUMERIC Dy30Abs  Dy30Schl (ADATE10).
COMPUTE Dy30Abs  = Time1 + TIME.DAYS(30).

DO IF   $CASENUM EQ 1.
*  Holidays observed:                            .
.  COMPUTE  #Holdy01  = DATE.MDY(02,02,2008) /* Groundhog Day    */.
.  COMPUTE  #Holdy02  = DATE.MDY(02,14,2008) /* Valentine's Day  */.
.  COMPUTE  #Holdy03  = DATE.MDY(03,15,2008) /* Ides of March    */.
.  COMPUTE  #Holdy04  = DATE.MDY(04,01,2008) /* April Fools' Day */.
.  COMPUTE  #Holdy05  = DATE.MDY(04,15,2008) /* IRS Day          */.
END IF.
FORMATS     #Holdy01 TO #Holdy05 (ADATE10).


NUMERIC #Day      (ADATE10).
NUMERIC #SchlDys  (F4).
COMPUTE #SchlDys = 0.

LOOP    #Day = time1 TO time2 BY TIME.DAYS(1).
.  DO IF   ANY(XDATE.WKDAY(#Day),7,1)   /* Weekend days */.
.  ELSE IF ANY(#Day,
                #Holdy01,#Holdy02,#Holdy03,
                #Holdy04,#Holdy05)       /* Holidays     */.
.  ELSE.
.     COMPUTE #SchlDys = #SchlDys + 1.
.     IF      MISSING(Dy30Schl)
          AND  #SchlDys GE 30
                       Dy30Schl = #Day.
.  END IF.
END LOOP.
COMPUTE DaysSchl = #SchlDys.

LIST.

=====================
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


Disclaimer: Information in this message or an attachment may be government data and thereby subject to the Minnesota Government Data Practices Act, Minnesota Statutes, Chapter 13, may be subject to attorney-client or work product privilege, may be confidential, privileged, proprietary, or otherwise protected, and the unauthorized review, copying, retransmission, or other use or disclosure of the information is strictly prohibited. If you are not the intended recipient of this message, please immediately notify the sender of the transmission error and then promptly delete this message from your computer system.

=====================
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