Syntax "if date (variable 1) is between two other dates

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Leiden2005
Posts: 1
Joined: Mon Oct 21, 2013 1:20 pm

Syntax "if date (variable 1) is between two other dates

Postby Leiden2005 » Mon Oct 21, 2013 1:47 pm

Hello,

I have an SPSS database containing dates of cases (date_case) from 1986 till 2012 in a "12-Jan-1986" format.
I want to write a syntax that creates a new variable with the format "1986,02" (year 1986 and weeknumber 2) if the date of the case falls into a certain week (between two dates...).

For example, week 2 in 1986 is from 06-Jan-1986 untill 12-Jan-1986.
If the "case_date" falls on 12-Jan-1986, I want the new variable to create "1986,02".

The problem is that the SPSS syntax does not recognize dates if you enter them as mentioned above.
I have put in the following syntax:

IF (Date_case >= 06-Jan-1986 & Date_case <= 12-Jan-1986) Year_week=1986.02.
EXECUTE.

but the following error occured:

IF (Date_case >= 06-Jan-1986 & Date_case <= 12-Jan-1986) Year_week=1986.02.

>Error # 4285 in column 6. Text: Date_case
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>Execution of this command stops.
EXECUTE.

Does somebody know how you can help SPSS syntax to recognize the data I put into the formula as a date?
Or does somebody know how you can solve this problem?

Thank you in advance! Daan
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Syntax "if date (variable 1) is between two other dates

Postby GerineL » Tue Oct 22, 2013 8:53 am

I always have a lot of trouble with dates as well, they don't work with a lot of functions.
A way around it is to calculate an age of sorts (in minutes if you have to) compared to a specific date, then use that age variable instead.

So for instance, calculate difference with 1-1-2013, and include everything between 7.12 and 8.13 years (compute what is applicable to you).
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

Re: Syntax "if date (variable 1) is between two other dates

Postby pythonforspss.org » Sat Oct 26, 2013 5:49 am

Hi Daan,

I suggest you create two variables (year and week) rather than one. Just use xdate.week and xdate.year as explained here: http://www.spss-tutorials.com/extract-a ... om-a-date/.

Greetings from sunny Amsterdam!
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com

Who is online

Users browsing this forum: No registered users and 1 guest

cron