easy question

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

easy question

Tuerk, Elena

Does anyone know why you can’t select cases from a string variable, (e.g., town = Arlington)? I know these can be recoded into numeric variables in order to select those cases but I’m just curious why that limitation exists.

 

Reply | Threaded
Open this post in threaded view
|

Re: easy question

Julie Rao
You can select cases using a string variable as a select if condition; you just need to add quotes to indicate you selecting on a string value.

If you want to select those case where the town variable equals Arlington, this should work.

SELECT IF town = 'Arlington'.

You may run into problems if you your variable has added spaces at the beginning or end or is in all caps in some but correct capitalization in another, but that is what RTRIM & LTRIM & UPCASE are for. 

HTH!

Tuerk, Elena wrote:

Does anyone know why you can’t select cases from a string variable, (e.g., town = Arlington)? I know these can be recoded into numeric variables in order to select those cases but I’m just curious why that limitation exists.

 

Reply | Threaded
Open this post in threaded view
|

Re: easy question

Arthur Burke
In reply to this post by Tuerk, Elena
Elena ... You can select on values of a string variable ...
 
DATA LIST /NAME 1-5 (A) SCORE 6-8.
BEGIN DATA.
TOM  10
DICK 15
HARRY 20
END DATA.
 
SELECT IF NAME='TOM'.
EXECUTE .
 
What is going wrong in your case?
 
Art

------------------------------------------------------------------

Art Burke

Evaluation Advisor
Northwest Regional Educational Laboratory
101 SW Main St, Suite 500
Portland, OR 97204-3213

Phone:  503-275-9592 / 800-547-6339

Fax: 503-275-0450

[hidden email] 

www.nwrel.org

 


 


 

From: Tuerk, Elena [mailto:[hidden email]]
Sent: Monday, August 17, 2009 12:34 PM
To: [hidden email]
Subject: easy question

Does anyone know why you can’t select cases from a string variable, (e.g., town = Arlington)? I know these can be recoded into numeric variables in order to select those cases but I’m just curious why that limitation exists.

 

Reply | Threaded
Open this post in threaded view
|

Re: easy question

Oliver, Richard

And remember that string selection is case-sensitive; so “Tom” is not the same as “TOM”. To avoid case issues, use the LOWER or UPCASE function, as in:

 

data list free /name (a10).

begin data

Tom

TOM

tom

Fred

Ethel

end data.

select if lower(name)='tom'.

list.

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Arthur Burke
Sent: Monday, August 17, 2009 2:57 PM
To: [hidden email]
Subject: Re: easy question

 

Elena ... You can select on values of a string variable ...

 

DATA LIST /NAME 1-5 (A) SCORE 6-8.
BEGIN DATA.
TOM  10
DICK 15
HARRY 20
END DATA.

 

SELECT IF NAME='TOM'.
EXECUTE .

 

What is going wrong in your case?

 

Art

------------------------------------------------------------------

Art Burke

Evaluation Advisor
Northwest Regional Educational Laboratory
101 SW Main St, Suite 500
Portland, OR 97204-3213

Phone:  503-275-9592 / 800-547-6339

Fax: 503-275-0450

[hidden email] 

www.nwrel.org

 


 


 


From: Tuerk, Elena [mailto:[hidden email]]
Sent: Monday, August 17, 2009 12:34 PM
To: [hidden email]
Subject: easy question

Does anyone know why you can’t select cases from a string variable, (e.g., town = Arlington)? I know these can be recoded into numeric variables in order to select those cases but I’m just curious why that limitation exists.