Date problem: how to compute if using date ranges

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

Date problem: how to compute if using date ranges

Julia-19
Hi everyone-

I am currently working on a time series analysis and therefore, I need to be
able to create a new variable called "weeks" listing the week number
starting from the week 12/22/1996 through 6/3/2007.

I figured the best way to do this (not sure how efficient it is with over
500 weeks) would be to create a compute statement followed by an if
statement. For example:

COMPUTE WEEK=0.
IF (DATE>12/22/1996) and (DATE<=12/29/1996) WEEK=1.
IF (DATE>12/29/1996) and (DATE<=01/05/1997) WEEK=2.
ETC.

My dates are currently in mm/dd/yyyy date format.

When I tried running a similar program, SPSS would not recognize the date
ranges. Anyone have any ideas? I am considering putting the DB into SAS but
it is such a hassle. Help?!

-Julia

=====================
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: Date problem: how to compute if using date ranges

Ornelas, Fermin-2
DATE2= INTNX( 'MONTH', '31DEC1983'D, NUM) ;
 FORMAT DATE2 MONYY.;

I used these lines for some arima modeling with SAS, but I am sure
someone else will give you the spss syntax. These were monthly data and
num is just a sas counter.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Julia
Sent: Tuesday, October 23, 2007 1:45 PM
To: [hidden email]
Subject: Date problem: how to compute if using date ranges

Hi everyone-

I am currently working on a time series analysis and therefore, I need
to
be
able to create a new variable called "weeks" listing the week number
starting from the week 12/22/1996 through 6/3/2007.

I figured the best way to do this (not sure how efficient it is with
over
500 weeks) would be to create a compute statement followed by an if
statement. For example:

COMPUTE WEEK=0.
IF (DATE>12/22/1996) and (DATE<=12/29/1996) WEEK=1.
IF (DATE>12/29/1996) and (DATE<=01/05/1997) WEEK=2.
ETC.

My dates are currently in mm/dd/yyyy date format.

When I tried running a similar program, SPSS would not recognize the
date
ranges. Anyone have any ideas? I am considering putting the DB into SAS
but
it is such a hassle. Help?!

-Julia

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

NOTICE: This e-mail (and any attachments) may contain PRIVILEGED OR
CONFIDENTIAL information and is intended only for the use of the
specific
individual(s) to whom it is addressed.  It may contain information that
is
privileged and confidential under state and federal law.  This
information
may be used or disclosed only in accordance with law, and you may be
subject to penalties under law for improper use or further disclosure of

the information in this e-mail and its attachments. If you have received

this e-mail in error, please immediately notify the person named above
by
reply e-mail, and then delete the original e-mail.  Thank you.

=====================
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: Date problem: how to compute if using date ranges

Norton, John
In reply to this post by Julia-19
Hi Julia,

You may be able to use the XDATE.WEEK() function to extract the week number within the year.  So, for example (and assuming that "date" is a variable recognized as a date formatted variable in SPSS) the following command:

COMPUTE week_num = XDATE.WEEK(date).

Would return the value of 43, for a date value with today's date, 10/23/07.  The value 43 indicates that this is the 43rd week of 2007.  If this is the first week of the analysis or study, you could then subtract 42 from this value and get a value of 1.  This is easily done this way:

COMPUTE weeks = XDATE.WEEK(date) - 42.

I hope this is useful and informative, and helpful.

Good luck,

John Norton


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Julia
Sent: Tuesday, October 23, 2007 3:45 PM
To: [hidden email]
Subject: Date problem: how to compute if using date ranges

Hi everyone-

I am currently working on a time series analysis and therefore, I need to be
able to create a new variable called "weeks" listing the week number
starting from the week 12/22/1996 through 6/3/2007.

I figured the best way to do this (not sure how efficient it is with over
500 weeks) would be to create a compute statement followed by an if
statement. For example:

COMPUTE WEEK=0.
IF (DATE>12/22/1996) and (DATE<=12/29/1996) WEEK=1.
IF (DATE>12/29/1996) and (DATE<=01/05/1997) WEEK=2.
ETC.

My dates are currently in mm/dd/yyyy date format.

When I tried running a similar program, SPSS would not recognize the date
ranges. Anyone have any ideas? I am considering putting the DB into SAS but
it is such a hassle. Help?!

-Julia

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

Re: Date problem: how to compute if using date ranges

Marks, Jim
In reply to this post by Julia-19
If you are doing time series using SPSS trends the DATE command can also
be used.

DATE W 1.

This will create two variables
        week_ (numeric)
        date_   (string)


This command "assumes" you have one case per week in your data set case
1 is week 1...

DATE also supports periodic data:

DATE Y 2001 M 1 12.

will create Year and month variables and identify 12 (month) cycles
starting Jan 2001.

Not sure if this works without the TRENDS module (I think it does)

--jim


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Julia
Sent: Tuesday, October 23, 2007 3:45 PM
To: [hidden email]
Subject: Date problem: how to compute if using date ranges

Hi everyone-

I am currently working on a time series analysis and therefore, I need
to be able to create a new variable called "weeks" listing the week
number starting from the week 12/22/1996 through 6/3/2007.

I figured the best way to do this (not sure how efficient it is with
over 500 weeks) would be to create a compute statement followed by an if
statement. For example:

COMPUTE WEEK=0.
IF (DATE>12/22/1996) and (DATE<=12/29/1996) WEEK=1.
IF (DATE>12/29/1996) and (DATE<=01/05/1997) WEEK=2.
ETC.

My dates are currently in mm/dd/yyyy date format.

When I tried running a similar program, SPSS would not recognize the
date ranges. Anyone have any ideas? I am considering putting the DB into
SAS but it is such a hassle. Help?!

-Julia

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