If Condition is Satisfied -> Multiple Variables/Conditions

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

LolaL
Posts: 1
Joined: Wed May 24, 2017 3:43 pm

If Condition is Satisfied -> Multiple Variables/Conditions

Postby LolaL » Wed May 24, 2017 6:28 pm

Hi there,

I need help filtering for rows with specific data. More specifically, I am trying to achieve this by going to "Select Cases", then "If condition is satisfied". I am looking to filter rows of data that contain either of these codes: "A40","A41","A42","A43","A44","A45"

My original data looks like this where all the codes are in one column:
OriginalData1Column
A01,,A02,,A03,,A08,,A11,,A16,,A18,,A19,,A20,,A99
A01,,A02,,A03,,A11,,A13,,A14,,A18,,A19,,A21,,A22,,A35,,A99
A01,,A02,,A03,,A11,,A16,,A45,,A99

I was told to break up the codes where each code is in its own column:
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12
A01 A02 A03 A08 A11 A16 A18 A19 A20 A99
A01 A02 A03 A11 A13 A14 A18 A19 A21 A22 A35 A99
A01 A02 A03 A11 A16 A45 A99

I've successfully accomplished that.

However, I get an error when I go to "If Condition is satisfied". Error: Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command.

SELECT IF (var1= 'A40' or var1= 'A41' or var1= 'A41' or var1= 'A41' or var1= 'A41' or var1= 'A41'
var1= 'A40' or var1= 'A41' or var1= 'A42' or var1= 'A43' or var1= 'A44' or var1= 'A45' or
var2= 'A40' or var2= 'A41' or var2= 'A42' or var2= 'A43' or var2= 'A44' or var2= 'A45' or
var3= 'A40' or var3= 'A41' or var3= 'A42' or var3= 'A43' or var3= 'A44' or var3= 'A45' or
var4= 'A40' or var4= 'A41' or var4= 'A42' or var4= 'A43' or var4= 'A44' or var4= 'A45' or
var5= 'A40' or var5= 'A41' or var5= 'A42' or var5= 'A43' or var5= 'A44' or var5= 'A45' or
var6= 'A40' or var6= 'A41' or var6= 'A42' or var6= 'A43' or var6= 'A44' or var6= 'A45' or
var7= 'A40' or var7= 'A41' or var7= 'A42' or var7= 'A43' or var7= 'A44' or var7= 'A45' or
var8= 'A40' or var8= 'A41' or var8= 'A42' or var8= 'A43' or var8= 'A44' or var8= 'A45' or
var9= 'A40' or var9= 'A41' or var9= 'A42' or var9= 'A43' or var9= 'A44' or var9= 'A45' or
var10= 'A40' or var10= 'A41' or var10= 'A42' or var10= 'A43' or var10= 'A44' or var10= 'A45' or
var11= 'A40' or var11= 'A41' or var11= 'A42' or var11= 'A43' or var11= 'A44' or var11= 'A45' or
var12= 'A40' or var12= 'A41' or var12= 'A42' or var12= 'A43' or var12= 'A44' or var12= 'A45' or
var13= 'A40' or var13= 'A41' or var13= 'A42' or var13= 'A43' or var13= 'A44' or var13= 'A45' or
var14= 'A40' or var14= 'A41' or var14= 'A42' or var14= 'A43' or var14= 'A44' or var14= 'A45' or
var15= 'A40' or var15= 'A41' or var15= 'A42' or var15= 'A43' or var15= 'A44' or var15= 'A45' or
var16= 'A40' or var16= 'A41' or var16= 'A42' or var16= 'A43' or var16= 'A44' or var16= 'A45').

What am I doing wrong? Is there a different method of accomplishing this?

I am using OS Windows 7 and SPSS Version 22.

Thanks much!
JonPedersen
Posts: 119
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: If Condition is Satisfied -> Multiple Variables/Conditions

Postby JonPedersen » Sun May 28, 2017 7:49 pm

Hi,
You are missing an "or" at the end of the first line.
There are, however, several ways this can be achieved with somewhat less work.
one is

Code: Select all

compute selvar=0.
do repeat /x=Var1, Var2,	Var3,Var4,Var5,Var6,Var7,Var8,Var9,Var10, Var11, Var12.
  if (x GE 'A40' ) and (x LE 'A45') selvar=1. 
end repeat.
select if selvar.

I did not test it but should be generally ok.

another version (without converting your original variable) would be

Code: Select all


compute selvar = (CHAR.RINDEX(Original,'A40) >0) or (CHAR.RINDEX(Original,'A41) >0) or (CHAR.RINDEX(Original,'A42) >0) ..... until you have all of them 
 
select if selvar.

hth
jon

Who is online

Users browsing this forum: No registered users and 2 guests

cron