case selection

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

case selection

karen lewis
Is there a way of selecting more than one case in a data set?  I 100's of
cases.  I am trying to select cases that have data.  What I've tried so
far is (1) select cases, (2) If condition is satisfied/If..... (3) select
variable.  After this, I would like to select several different id numbers
but I don't know what to use to seperate the numbers (assuming that you
can seperate the numbers). I've tried commas, semi-colons, and (+).

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: case selection

John Amora
Karen,
 
Suppose you select three cases with ID numbers 5, 8 and 10 where id is the variable name.  Just  type the following on the "Select Cases: If" dialog box:
 
                        id=5 & id=8 & id=10
 
In that command, an = sign was used followed by &.  You can use symbols < , < or  ~ depending on what you want.
 
Try also this sample syntax:
 
USE ALL.
COMPUTE filter_$=(id=5 & id=8 & id = 10).
VARIABLE LABEL filter_$ 'id=5 & id=8 & id = 10 (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE .
 
Cheers,
Johhny

 
Johnny T. Amora
Statistician, Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

--- On Sat, 11/29/08, Lewis <[hidden email]> wrote:

From: Lewis <[hidden email]>
Subject: case selection
To: [hidden email]
Date: Saturday, 29 November, 2008, 6:54 AM

Is there a way of selecting more than one case in a data set?  I 100's of
cases.  I am trying to select cases that have data.  What I've tried so
far is (1) select cases, (2) If condition is satisfied/If..... (3) select
variable.  After this, I would like to select several different id numbers
but I don't know what to use to seperate the numbers (assuming that you
can seperate the numbers). I've tried commas, semi-colons, and (+).

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



      Bring your friends to the fun. Invite your friends from Hotmail, Gmail to Yahoo! Mail today! http://www.trueswitch.com/yahoo-ph

====================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: case selection

Richard Ristow
In reply to this post by karen lewis
At 05:54 PM 11/28/2008, Lewis wrote:

>Is there a way of selecting more than one case in a data set?

Of course; SELECT IF is for that. But it's not clear from your
posting what you're really trying to do.

>I am trying to select cases that have data.

If this is what you mean, you can select cases that have no missing
values in variables A to Z with syntax (untested),

SELECT IF NMISS(A TO Z) EQ 0.

>What I've tried so far is (1) select cases, (2) If condition is
>satisfied/If..... (3) select variable.  After this, I would like to
>select several different id numbers but I don't know what to use to
>seperate the numbers (assuming that you can seperate the numbers).
>I've tried commas, semi-colons, and (+).

OK: when you're posting about syntax that doesn't work, ALWAYS
INCLUDE THE SYNTAX IN YOUR POST. If we tried to make suggestions at
this point, we'd only be guessing about what you're doing.

So, post again. Give the syntax that doesn't work, and include any
error messages you get from SPSS. Ideally, also include a short set
of test data, with the results you want with that data as input.

And, we'll go from there.

-Good luck,
  Richard

=====================
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: case selection

Albert-Jan Roskam
In reply to this post by karen lewis
hi,

Something like the following would work:
select if (any(id, 234, 123, 4556, 999)).
If your id is a string var, you have to 'quote' the values.
if it's a range, you could use:
select if (range(id, 200, 999)).
or simply:
select if id > 123.

Cheers!!
Albert-Jan

--- On Fri, 11/28/08, Lewis <[hidden email]> wrote:

> From: Lewis <[hidden email]>
> Subject: case selection
> To: [hidden email]
> Date: Friday, November 28, 2008, 11:54 PM
> Is there a way of selecting more than one case in a data
> set?  I 100's of
> cases.  I am trying to select cases that have data.  What
> I've tried so
> far is (1) select cases, (2) If condition is
> satisfied/If..... (3) select
> variable.  After this, I would like to select several
> different id numbers
> but I don't know what to use to seperate the numbers
> (assuming that you
> can seperate the numbers). I've tried commas,
> semi-colons, and (+).
>
> 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

=====================
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: case selection

Johnny Amora
In reply to this post by karen lewis
Karen,
 
Suppose you select three cases with ID numbers 5, 8 and 10 where id is the variable name.  Just  type the following on the "Select Cases: If" dialog box:
 
                        id=5 & id=8 & id=10
 
In that command, an = sign was used followed by &.  You can use symbols < , < or  ~ depending on what you want.
 
Try also this sample syntax:
 
USE ALL.
COMPUTE filter_$=(id=5 & id=8 & id = 10).
VARIABLE LABEL filter_$ 'id=5 & id=8 & id = 10 (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE .
 
Cheers,
Johhny

--- On Sat, 11/29/08, Lewis <[hidden email]> wrote:

From: Lewis <[hidden email]>
Subject: case selection
To: [hidden email]
Date: Saturday, 29 November, 2008, 6:54 AM

Is there a way of selecting more than one case in a data set?  I 100's of
cases.  I am trying to select cases that have data.  What I've tried so
far is (1) select cases, (2) If condition is satisfied/If..... (3) select
variable.  After this, I would like to select several different id numbers
but I don't know what to use to seperate the numbers (assuming that you
can seperate the numbers). I've tried commas, semi-colons, and (+).

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



      Bring your friends to the fun. Invite your friends from Hotmail, Gmail to Yahoo! Mail today! http://www.trueswitch.com/yahoo-ph

====================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: case selection

Nancy Darling-2
Johnny Amora wrote:
> Karen,
>
> Suppose you select three cases with ID numbers 5, 8 and 10 where id is the variable name.  Just  type the following on the "Select Cases: If" dialog box:
>
>                         id=5 & id=8 & id=10
>
> In that command, an = sign was used followed by &.  You can use symbols < , < or  ~ depending on what you want.
>

If you use an '&' sign, it won't select anything, because no case has an
id number equal to all three values.  You want an 'or', don't you?

select if id=5 or id=8 or id=10.

In older versions of SPSS, I have found if you have too many 'or' and
'and' statements it will eventually stop selecting correctly (I'm
recalling 5, but it's been a long time).

If you have a lot of random ids you want to select, you can compute a
temporary variable that is set to 0 and becomes 1 if it matches the id.
Then select for the temporary variable (similar to the syntax in the
original post).  The advantage of doing it that way is you can have an
unlimited number of if statements, so could potentially choose 100's of
individual ids if you needed to.

compute tempid=0.
if id=5 or id=8 or id=10 or id=27 or id=105 tempid=1.
if id=1005 or id=1008 or id=1010 or id=1027 or id=1105 tempid=1.
select if tempid=1.


>
> Try also this sample syntax:
>
> USE ALL.
> COMPUTE filter_$=(id=5 & id=8 & id = 10).
> VARIABLE LABEL filter_$ 'id=5 & id=8 & id = 10 (FILTER)'.
> VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
> FORMAT filter_$ (f1.0).
> FILTER BY filter_$.
> EXECUTE .
>
> Cheers,
> Johhny
>
>

=====================
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: case selection

Art Kendall
The careful distinction of 'and' vs 'or' is  fundamental in computer
languages.
For  many people the use of the traditional operators helps them because
they are easier to perceive than the symbolic ones.
or, and, lt, le, ge, gt, ne etc  are easier for many people to see than
the symbols & | < <= >= > <> etc.   & is often used to indicate
concatenation of strings which gives it two meanings depending on context..

It is extremely difficult for many people to read syntax that uses the
same same symbol two ways depending on context.
When programs started allowing = to mean a logic equal operator as
opposed to an assignment operator many beginners find it difficult
figure which context is meant.

As a rule it enhances readability to use = solely as an assignment
operator and to use eq for the logical operator.  This is often
beneficial even when the symbolic operators are use for the other
logical meanings.

Art Kendall


Nancy Darling wrote:

> Johnny Amora wrote:
>> Karen,
>>
>> Suppose you select three cases with ID numbers 5, 8 and 10 where id
>> is the variable name.  Just  type the following on the "Select Cases:
>> If" dialog box:
>>
>>                         id=5 & id=8 & id=10
>>
>> In that command, an = sign was used followed by &.  You can use
>> symbols < , < or  ~ depending on what you want.
>>
>
> If you use an '&' sign, it won't select anything, because no case has an
> id number equal to all three values.  You want an 'or', don't you?
>
> select if id=5 or id=8 or id=10.
>
> In older versions of SPSS, I have found if you have too many 'or' and
> 'and' statements it will eventually stop selecting correctly (I'm
> recalling 5, but it's been a long time).
>
> If you have a lot of random ids you want to select, you can compute a
> temporary variable that is set to 0 and becomes 1 if it matches the id.
> Then select for the temporary variable (similar to the syntax in the
> original post).  The advantage of doing it that way is you can have an
> unlimited number of if statements, so could potentially choose 100's of
> individual ids if you needed to.
>
> compute tempid=0.
> if id=5 or id=8 or id=10 or id=27 or id=105 tempid=1.
> if id=1005 or id=1008 or id=1010 or id=1027 or id=1105 tempid=1.
> select if tempid=1.
>
>
>>
>> Try also this sample syntax:
>>
>> USE ALL.
>> COMPUTE filter_$=(id=5 & id=8 & id = 10).
>> VARIABLE LABEL filter_$ 'id=5 & id=8 & id = 10 (FILTER)'.
>> VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
>> FORMAT filter_$ (f1.0).
>> FILTER BY filter_$.
>> EXECUTE .
>>
>> Cheers,
>> Johhny
>>
>>
>
> =====================
> 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: case selection

Richard Ristow
In reply to this post by Nancy Darling-2
A note on SPSS syntax: At 11:41 AM 11/29/2008, Nancy Darling wrote,

>If you have a lot of random ids you want to select, you can compute
>a temporary variable that is set to 0 and becomes 1 if it matches
>the id. Then select for the temporary variable (similar to the
>syntax in the original post).
>
>compute tempid=0.
>if id=5 or id=8 or id=10 or id=27 or id=105 tempid=1.
>if id=1005 or id=1008 or id=1010 or id=1027 or id=1105 tempid=1.

Right. But that overlooks RECODE, one of the best-designed features
of SPSS, which gives shorter and (I think) clearer syntax:

RECODE id
    (   5,    8,   10,   27,  105 = 1)
    (1005, 1008, 1010, 1027, 1105 = 1)
    (ELSE = 0)
               INTO tempid.

>select if tempid=1.


(There are many variations to RECODE syntax. A lot of people would write

RECODE id
    (   5,    8,   10,   27,  105,
     1005, 1008, 1010, 1027, 1105 = 1)
    (ELSE = 0)
               INTO tempid.

and some would go the other way and write,

RECODE id
    (   5 = 1)
    (   8 = 1)
    (  10 = 1)
    (  27 = 1)
    ( 105 = 1)
    (1005 = 1)
    (1008 = 1)
    (1010 = 1)
    (1027 = 1)
    (1105 = 1)
               INTO tempid.

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