Question about "Any (varlist, value)"

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

Question about "Any (varlist, value)"

Ruben Geert van den Berg
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Question about "Any (varlist, value)"

Art Kendall
I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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: Question about "Any (varlist, value)"

Maguin, Eugene
In reply to this post by Ruben Geert van den Berg
Well, Ruben, what does it do?  Is there an error/warning message? Come on,
help us out. Actually, I'll bet you are getting a '1' in V55020n#02 when any
variables in the list have '2' as a value. And so on. True??

I think this sequence would work.

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
If (v eq 1) v=a.
end rep.
exe.


Gene Maguin

>>Could anybody tell me why the syntax below doesn't render what I want it
to render?

Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY
of these variables contains '1', I'd like a new variable [V55020n#01 ] to
contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not
even sure what my syntax does (the result in data view is puzzling) but it's
not what I intended.

TIA!

Ruben






________________________________

New Windows 7: Find the right PC for you. Learn more.
<http://windows.microsoft.com/shop>

=====================
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: Question about "Any (varlist, value)"

Ruben Geert van den Berg
In reply to this post by Art Kendall
Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 

Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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

New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Question about "Any (varlist, value)"

Art Kendall
How does it run if you remove the first right (close) parenthesis in each statement?
compute dummy1 = any((x1 to x3,1).
Also I an curious about why you would create such a long dummy vector.  if you just want to find out if some values are not used by any cases you could do a MULT RESPONSE /frequency or CTABLES.

Art

Ruben van den Berg wrote:
Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 

Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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

New Windows 7: Find the right PC for you. Learn more.
===================== 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: Question about "Any (varlist, value)"

Art Kendall
In reply to this post by Ruben Geert van den Berg
BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:
Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 

Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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

New Windows 7: Find the right PC for you. Learn more.
===================== 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: Question about "Any (varlist, value)"

Ruben Geert van den Berg
Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 

id x1 x2 x3 flag1 flag2 flag3 flag4
1 1 1 1 01 01 01 01
2 1 1 2 01 01 01 01
3 3 2 1 00 00 01 00
4 3 3 3 01 01 01 01
5 4 4 4 01 01 01 01
6 2 2 2 01 01 01 01

 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 

Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:
Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 

Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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

New Windows 7: Find the right PC for you. Learn more.
===================== 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

Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: Question about "Any (varlist, value)"

Art Kendall
i still don't have my auth code from SPSS so I cannot test your example.
Does this represent the problem you started with?

These results are surprising!  What does the variable view show for the flag variables? N format? String? A default setting on your machine?
What happens if you put
numeric flag1 to flag4 (f1).
before the do repeat.

Also, does this work?
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
compute testvar =1.
compute flagvar = any(x1 to x3, testvar)
list.



Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 
id x1 x2 x3 flag1 flag2 flag3 flag4
1 1 1 1 01 01 01 01
2 1 1 2 01 01 01 01
3 3 2 1 00 00 01 00
4 3 3 3 01 01 01 01
5 4 4 4 01 01 01 01
6 2 2 2 01 01 01 01

 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 

Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:
Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 

Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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

New Windows 7: Find the right PC for you. Learn more.
===================== 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

Express yourself instantly with MSN Messenger! MSN Messenger
===================== 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: Question about "Any (varlist, value)"

ViAnn Beadle
In reply to this post by Ruben Geert van den Berg

You’ve got your arguments backward. It should be compute flag=any(a, x1 to x3).

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Sent: Wednesday, January 06, 2010 8:06 AM
To: [hidden email]
Subject: Re: Question about "Any (varlist, value)"

 

Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 

id

x1

x2

x3

flag1

flag2

flag3

flag4

1

1

1

1

01

01

01

01

2

1

1

2

01

01

01

01

3

3

2

1

00

00

01

00

4

3

3

3

01

01

01

01

5

4

4

4

01

01

01

01

6

2

2

2

01

01

01

01


 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 


Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:

Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 


Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).


list.


Art Kendall
Social Research Consultants

Ruben van den Berg wrote:

Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 




New Windows 7: Find the right PC for you. Learn more.

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


New Windows 7: Find the right PC for you. Learn more.

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


Express yourself instantly with MSN Messenger! MSN Messenger

Reply | Threaded
Open this post in threaded view
|

Re: Question about "Any (varlist, value)"

Ruben Geert van den Berg
In reply to this post by Art Kendall
Dear Art,
 
Running
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
compute testvar =1.
compute flagvar = any(x1 to x3, testvar).
list.
numeric flag1 to flag4 (f1).
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
sav tra out 'c:\temp\blabla.xls'
/typ xls
/fie
/rep.
 
renders
 
id x1 x2 x3 testvar flagvar flag1 flag2 flag3 flag4
1 1 1 1 01 01 1 1 1 1
2 1 1 2 01 01 1 1 1 1
3 3 2 1 01 00 0 0 1 0
4 3 3 3 01 01 1 1 1 1
5 4 4 4 01 01 1 1 1 1
6 2 2 2 01 01 1 1 1 1

 
So as you can see, even the flagvar is weird. There aren't any string variables involved (all numeric).
 
Kind regards,
 
Ruben
 
 




 



 

Date: Wed, 6 Jan 2010 10:50:12 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

i still don't have my auth code from SPSS so I cannot test your example.
Does this represent the problem you started with?

These results are surprising!  What does the variable view show for the flag variables? N format? String? A default setting on your machine?
What happens if you put
numeric flag1 to flag4 (f1).
before the do repeat.

Also, does this work?
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
compute testvar =1.
compute flagvar = any(x1 to x3, testvar)
list.



Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 
id x1 x2 x3 flag1 flag2 flag3 flag4
1 1 1 1 01 01 01 01
2 1 1 2 01 01 01 01
3 3 2 1 00 00 01 00
4 3 3 3 01 01 01 01
5 4 4 4 01 01 01 01
6 2 2 2 01 01 01 01

 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 

Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:
Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 

Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).

list.

Art Kendall
Social Research Consultants

Ruben van den Berg wrote:
Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.
===================== 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

New Windows 7: Find the right PC for you. Learn more.
===================== 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

Express yourself instantly with MSN Messenger! MSN Messenger
===================== 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

New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Question about "Any (varlist, value)"

Roberts, Michael

Ruben,

 

Your 11th and 15th lines in the code where you use the ‘any’ function is causing you the difficulty.  You have your arguments (parenthesized values) reversed.  The correct coding is in the revised program below (as pointed out by ViAnn Beadle):

 

data list list /id (f2) x1 to x3 (3f2).

begin data

01 1 1 1

02 1 1 2

03 3 2 1

04 3 3 3

05 4 4 4

06 2 2 2

end data.

compute testvar =1.

compute flagvar = any(testvar, x1 to x3).

list.

numeric flag1 to flag4 (f1).

do repeat flag = flag1 to flag4 /a = 1 to 4.

compute flag = any (a,x1 to x3).

end repeat.

exe.

 

 

Hope this helps.

 

Mike

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Sent: Wednesday, January 06, 2010 11:05 AM
To: [hidden email]
Subject: Re: Question about "Any (varlist, value)"

 

Dear Art,
 
Running
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
compute testvar =1.
compute flagvar = any(x1 to x3, testvar).
list.
numeric flag1 to flag4 (f1).
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
sav tra out 'c:\temp\blabla.xls'
/typ xls
/fie
/rep.
 
renders
 

id

x1

x2

x3

testvar

flagvar

flag1

flag2

flag3

flag4

1

1

1

1

01

01

1

1

1

1

2

1

1

2

01

01

1

1

1

1

3

3

2

1

01

00

0

0

1

0

4

3

3

3

01

01

1

1

1

1

5

4

4

4

01

01

1

1

1

1

6

2

2

2

01

01

1

1

1

1


 
So as you can see, even the flagvar is weird. There aren't any string variables involved (all numeric).
 
Kind regards,
 
Ruben
 
 




 



 


Date: Wed, 6 Jan 2010 10:50:12 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

i still don't have my auth code from SPSS so I cannot test your example.
Does this represent the problem you started with?

These results are surprising!  What does the variable view show for the flag variables? N format? String? A default setting on your machine?
What happens if you put
numeric flag1 to flag4 (f1).
before the do repeat.

Also, does this work?
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
compute testvar =1.
compute flagvar = any(x1 to x3, testvar)
list.



Art Kendall
Social Research Consultants

Ruben van den Berg wrote:

Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 

id

x1

x2

x3

flag1

flag2

flag3

flag4

1

1

1

1

01

01

01

01

2

1

1

2

01

01

01

01

3

3

2

1

00

00

01

00

4

3

3

3

01

01

01

01

5

4

4

4

01

01

01

01

6

2

2

2

01

01

01

01


 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 


Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:

Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 


Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).


list.


Art Kendall
Social Research Consultants

Ruben van den Berg wrote:

Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 




New Windows 7: Find the right PC for you. Learn more.

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


New Windows 7: Find the right PC for you. Learn more.

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


Express yourself instantly with MSN Messenger! MSN Messenger

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


New Windows 7: Find the right PC for you. Learn more.

Reply | Threaded
Open this post in threaded view
|

Re: Question about "Any (varlist, value)"

Art Kendall
In reply to this post by ViAnn Beadle
Good catch!
I don't have my auth code yet from SPSS so cannot even use the help to check the documentation.

The original post subject was: Question about "Any (varlist, value)".

Just to refresh my memory, which of these should work. I recall something other than 3 works.
1) list for both values and vars
Any ((values), (varlist)).

2) list for values and 1 var
Any ((values), (var)).

3) single value and varlist
Any ((value), (varlist)).

4) for completness (would be the same as "if var eq value.")
Any ((value), (var)).


Art Kendall
Social Research Consultants

ViAnn Beadle wrote:

You’ve got your arguments backward. It should be compute flag=any(a, x1 to x3).

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Ruben van den Berg
Sent: Wednesday, January 06, 2010 8:06 AM
To: [hidden email]
Subject: Re: Question about "Any (varlist, value)"

 

Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 

id

x1

x2

x3

flag1

flag2

flag3

flag4

1

1

1

1

01

01

01

01

2

1

1

2

01

01

01

01

3

3

2

1

00

00

01

00

4

3

3

3

01

01

01

01

5

4

4

4

01

01

01

01

6

2

2

2

01

01

01

01


 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 


Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:

Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 


Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).


list.


Art Kendall
Social Research Consultants

Ruben van den Berg wrote:

Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 




New Windows 7: Find the right PC for you. Learn more.

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


New Windows 7: Find the right PC for you. Learn more.

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


Express yourself instantly with MSN Messenger! MSN Messenger

===================== 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: Question about "Any (varlist, value)"

ViAnn Beadle

ANY(testvalue, inputvalue, inputvalue, inputvalue…) with the special case of var to var as inputvalues.

 

The first value irrespective of whether it’s a constant or a variable is always the test value.  Examples 1 and 2 don’t give you what you want unless you want only the 1st value to be the test value. Typical uses are:

 

ANY(1, varn to varn+1)

ANY(varn, value, value, value, ….)

Ruben was testing the value of x1 against the values of x2, x3, and a.

 

From: Art Kendall [mailto:[hidden email]]
Sent: Wednesday, January 06, 2010 10:31 AM
To: ViAnn Beadle
Cc: [hidden email]
Subject: Re: [SPSSX-L] Question about "Any (varlist, value)"

 

Good catch!
I don't have my auth code yet from SPSS so cannot even use the help to check the documentation.

The original post subject was: Question about "Any (varlist, value)".

Just to refresh my memory, which of these should work. I recall something other than 3 works.
1) list for both values and vars
Any ((values), (varlist)).

2) list for values and 1 var
Any ((values), (var)).

3) single value and varlist
Any ((value), (varlist)).

4) for completness (would be the same as "if var eq value.")
Any ((value), (var)).


Art Kendall
Social Research Consultants

ViAnn Beadle wrote:

You’ve got your arguments backward. It should be compute flag=any(a, x1 to x3).

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Ruben van den Berg
Sent: Wednesday, January 06, 2010 8:06 AM
To: [hidden email]
Subject: Re: Question about "Any (varlist, value)"

 

Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 

id

x1

x2

x3

flag1

flag2

flag3

flag4

1

1

1

1

01

01

01

01

2

1

1

2

01

01

01

01

3

3

2

1

00

00

01

00

4

3

3

3

01

01

01

01

5

4

4

4

01

01

01

01

6

2

2

2

01

01

01

01


 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 


Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:

Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 


Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).


list.


Art Kendall
Social Research Consultants

Ruben van den Berg wrote:

Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.

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


New Windows 7: Find the right PC for you. Learn more.

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


Express yourself instantly with MSN Messenger! MSN Messenger

Reply | Threaded
Open this post in threaded view
|

SOLVED: Question about "Any (varlist, value)"

Ruben Geert van den Berg
Thank you so much, ViAnn! 

Especially the additional explanation ("The first value irrespective of whether it’s a constant or a variable is always the test value.") is very instructive since I didn't even know that the testvalue could be a variable instead of a constant.

Best regards,

Ruben

 





Date: Wed, 6 Jan 2010 11:10:07 -0700
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

ANY(testvalue, inputvalue, inputvalue, inputvalue…) with the special case of var to var as inputvalues.

 

The first value irrespective of whether it’s a constant or a variable is always the test value.  Examples 1 and 2 don’t give you what you want unless you want only the 1st value to be the test value. Typical uses are:

 

ANY(1, varn to varn+1)

ANY(varn, value, value, value, ….)

Ruben was testing the value of x1 against the values of x2, x3, and a.

 

From: Art Kendall [mailto:[hidden email]]
Sent: Wednesday, January 06, 2010 10:31 AM
To: ViAnn Beadle
Cc: [hidden email]
Subject: Re: [SPSSX-L] Question about "Any (varlist, value)"

 

Good catch!
I don't have my auth code yet from SPSS so cannot even use the help to check the documentation.

The original post subject was: Question about "Any (varlist, value)".

Just to refresh my memory, which of these should work. I recall something other than 3 works.
1) list for both values and vars
Any ((values), (varlist)).

2) list for values and 1 var
Any ((values), (var)).

3) single value and varlist
Any ((value), (varlist)).

4) for completness (would be the same as "if var eq value.")
Any ((value), (var)).


Art Kendall
Social Research Consultants

ViAnn Beadle wrote:

You’ve got your arguments backward. It should be compute flag=any(a, x1 to x3).

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Ruben van den Berg
Sent: Wednesday, January 06, 2010 8:06 AM
To: [hidden email]
Subject: Re: Question about "Any (varlist, value)"

 

Dear Art,
 
I'm probably missing something but if I just run
 
data list list /id (f2) x1 to x3 (3f2).
begin data
01 1 1 1
02 1 1 2
03 3 2 1
04 3 3 3
05 4 4 4
06 2 2 2
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
exe.
 
then I get
 

id

x1

x2

x3

flag1

flag2

flag3

flag4

1

1

1

1

01

01

01

01

2

1

1

2

01

01

01

01

3

3

2

1

00

00

01

00

4

3

3

3

01

01

01

01

5

4

4

4

01

01

01

01

6

2

2

2

01

01

01

01


 
Now why does respondent 01 have a '1' on flag2 Or flag3/flag4 He (or she) doesn't have any 2/3/4 within x1 to x3.
 
Best regards,
 
Ruben
 
BTW no errors/warnings.




 



 


Date: Wed, 6 Jan 2010 09:54:38 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

BTW what does the flag set of variables look like?

Art

Ruben van den Berg wrote:

Dear Art,
 
The flag variables provide a nice replication of the problem: the result is not what you (or at least I) would expect.
 
Your compute statements for dummy variables lack a parenthesis but if I run
 
compute dummy1 = any((x1 to x3),1).

I get the error that
 

Error # 4027 in column 26. Text: to

An expression contains an invalid or inappropriate use of the TO keyword. The

TO keyword may be used in the MEAN, SUM, and other similar functions in lieu

of entering individual variable names, but it may not be used in other

contexts.

This command not executed.

 
However,
 
compute dummy1 = any((x1 ,x2, x3),1).
 
doesn't work either.
 
Well, I guess that I've been on a mission impossible once again but I do think it awkward that the 'do repeat' approach runs without errors or warnings while something strange seems to happen.
 
A fast workaround for this one is
 
do rep a=bla1 to bla4/b=1 to 4.
cou a=x1 to x3(b).
recod a (0=0)(els=1).
end rep.
 
To be continued?
 
Kind regards,
 
Ruben


 



 


Date: Wed, 6 Jan 2010 07:56:03 -0500
From: [hidden email]
Subject: Re: Question about "Any (varlist, value)"
To: [hidden email]

I do not have SPSS available right now so this is untested.
Please copy, past and run this example syntax.

Is the "want" vector correct?

Does  LIST show the problem you are having? 

How is the "want" vector different from the "flag" vector?
Is the "flag" vector different from the "dummy" vector? How?

data list list /id (f2) x1 to x3 want1 to want4 (7f2).
begin data
01 1 1 1 1 0 0 0
02 1 1 2 1 1 0 0
03 3 2 1 1 1 1 0
04 3 3 3 0 0 1 0
05 4 4 4 0 0 0 1
06 2 2 2 0 1 0 0
end data.
do repeat flag = flag1 to flag4 /a = 1 to 4.
compute flag = any (x1 to x3, a).
end repeat.
numeric dummy1 to dummy4 (f2).
compute dummy1 = any(x1 to x3),1).
compute dummy2 = any(x1 to x3),2).
compute dummy3 = any(x1 to x3),3).
compute dummy4 = any(x1 to x3),4).


list.


Art Kendall
Social Research Consultants

Ruben van den Berg wrote:

Dear all,
 
Could anybody tell me why the syntax below doesn't render what I want it to render?
 
Variables [V55020_3Q1 to V55020_8Q1] contain values between 1 and 66. If ANY of these variables contains '1', I'd like a new variable [V55020n#01 ] to contain '1' and otherwise '0'. And so on for values 2 through 66. I'm not even sure what my syntax does (the result in data view is puzzling) but it's not what I intended.
 
TIA!
 
Ruben

do rep v=V55020n#01 to V55020n#66/a=1 to 66.
comp v=any(V55020_3Q1 to V55020_8Q1,a).
end rep.
exe. 





New Windows 7: Find the right PC for you. Learn more.

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


New Windows 7: Find the right PC for you. Learn more.

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


Express yourself instantly with MSN Messenger! MSN Messenger



New Windows 7: Find the right PC for you. Learn more.