selecting cases with a date variable

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

selecting cases with a date variable

Arthur Kramer

I am trying to select cases of students who completed a course of study prior to, for example, 17-MAY-2007. How can this be performed using the SELECT IF command—it is not accepted as a string variable (using single quotes) or number (without quotes).

 

Thanks for any help you can provide.

 

Arthur Kramer

 

Reply | Threaded
Open this post in threaded view
|

Re: selecting cases with a date variable

ariel barak
Hi Arthur,

The issue is that your date variable is stored as a string. I suggest that you convert the string variable to a date variable. Take a look at the ALTER TYPE command and you can also search the listserv for countless examples of converting dates from string to date variables. Once this is done, you can use something like this:

SELECT IF CompleteDate<DATE.MDY(5,17,2007).
EXECUTE.

I hope this helps.

-Ariel

On Fri, Feb 18, 2011 at 3:14 PM, Arthur Kramer <[hidden email]> wrote:

I am trying to select cases of students who completed a course of study prior to, for example, 17-MAY-2007. How can this be performed using the SELECT IF command—it is not accepted as a string variable (using single quotes) or number (without quotes).

 

Thanks for any help you can provide.

 

Arthur Kramer

 


Reply | Threaded
Open this post in threaded view
|

Re: selecting cases with a date variable

Arthur Kramer

Thanks, Ariel, but see in the data editor/variable view that the variable is date format. I think what I may have to do is convert the dates to seconds since Oct 14, 1582, which is something like 13 billion seconds.

 

Arthur Kramer

 

 

From: Ariel Barak [mailto:[hidden email]]
Sent: Friday, February 18, 2011 4:47 PM
To: Arthur Kramer
Cc: [hidden email]
Subject: Re: selecting cases with a date variable

 

Hi Arthur,

The issue is that your date variable is stored as a string. I suggest that you convert the string variable to a date variable. Take a look at the ALTER TYPE command and you can also search the listserv for countless examples of converting dates from string to date variables. Once this is done, you can use something like this:

SELECT IF CompleteDate<DATE.MDY(5,17,2007).
EXECUTE.

I hope this helps.

-Ariel

On Fri, Feb 18, 2011 at 3:14 PM, Arthur Kramer <[hidden email]> wrote:

I am trying to select cases of students who completed a course of study prior to, for example, 17-MAY-2007. How can this be performed using the SELECT IF command—it is not accepted as a string variable (using single quotes) or number (without quotes).

 

Thanks for any help you can provide.

 

Arthur Kramer

 

 

Reply | Threaded
Open this post in threaded view
|

Re: selecting cases with a date variable

Marks, Jim
In reply to this post by Arthur Kramer
Something like this:

Select if date GE date.mdy(5,1,2007)

Will permanently delete all cases prior to 1 may 2007.

Jim


From: SPSSX(r) Discussion <[hidden email]>
To: [hidden email] <[hidden email]>
Sent: Fri Feb 18 15:56:49 2011
Subject: Re: selecting cases with a date variable

Thanks, Ariel, but see in the data editor/variable view that the variable is date format. I think what I may have to do is convert the dates to seconds since Oct 14, 1582, which is something like 13 billion seconds.

 

Arthur Kramer

 

 

From: Ariel Barak [mailto:[hidden email]]
Sent: Friday, February 18, 2011 4:47 PM
To: Arthur Kramer
Cc: [hidden email]
Subject: Re: selecting cases with a date variable

 

Hi Arthur,

The issue is that your date variable is stored as a string. I suggest that you convert the string variable to a date variable. Take a look at the ALTER TYPE command and you can also search the listserv for countless examples of converting dates from string to date variables. Once this is done, you can use something like this:

SELECT IF CompleteDate<DATE.MDY(5,17,2007).
EXECUTE.

I hope this helps.

-Ariel

On Fri, Feb 18, 2011 at 3:14 PM, Arthur Kramer <[hidden email]> wrote:

I am trying to select cases of students who completed a course of study prior to, for example, 17-MAY-2007. How can this be performed using the SELECT IF command—it is not accepted as a string variable (using single quotes) or number (without quotes).

 

Thanks for any help you can provide.

 

Arthur Kramer

 

 

Reply | Threaded
Open this post in threaded view
|

Re: selecting cases with a date variable

drfg2008
In reply to this post by Arthur Kramer

(17-MAY-2007 = 13398739200)
if you have an other date, use your date formatted variable and check it.

solution:

IF  (date2 <= 13398739200) test=1.
EXECUTE.


regards
Dr. Frank Gaeth

Reply | Threaded
Open this post in threaded view
|

Re: selecting cases with a date variable

Bruce Weaver
Administrator
The method solution Jim Marks posted is far more transparent, IMO.  I.e.,

select if datevar LE date.mdy(5,17,2007).


drfg2008 wrote
(17-MAY-2007 = 13398739200)
if you have an other date, use your date formatted variable and check it.

solution:

IF  (date2 <= 13398739200) test=1.
EXECUTE.


regards
--
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/).