3-variable comparison with True/False flag

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

3-variable comparison with True/False flag

elle lists

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: 3-variable comparison with True/False flag

Art Kendall
Something like the tested syntax below should do what you want.
Pay close attention to how you generate the recode after the autorecode.

Art Kendall
Social Research Consultants

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.
autorecode var1 to var3 /into num1 to num3/group/print.
recode num1 to num3 (1 thru 3=1) (4=2) (5 thru 7 =3) into final1 to final3.
value labels num1 to num3
   1 'variations on apple'
   2 'variations on orange'
   3 'variations on pear'.
compute allsame = num1 eq num2 and num1 eq num3.
value labels allsame
   0 'false'
   1 'true'.
formats num1 to num3 final1 to final3 (f2) allsame (f1).
list.


On 10/24/2011 10:12 AM, elle wrote:

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

===================== 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: 3-variable comparison with True/False flag

elle lists

Dr. Kendall, thank you very much for the speedy response and solution – very efficient and works like a charm.  BTW, I see the string content is recoded to numeric but was wondering if there’s an SPSS function to compare strings-to-strings? 

 

Many thanks!

 

Elle

 

From: Art Kendall [mailto:[hidden email]]
Sent: Monday, October 24, 2011 1:48 AM
To: elle
Cc: [hidden email]
Subject: Re: [SPSSX-L] 3-variable comparison with True/False flag

 

Something like the tested syntax below should do what you want.
Pay close attention to how you generate the recode after the autorecode.

Art Kendall
Social Research Consultants

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.
autorecode var1 to var3 /into num1 to num3/group/print.
recode num1 to num3 (1 thru 3=1) (4=2) (5 thru 7 =3) into final1 to final3.
value labels num1 to num3
   1 'variations on apple'
   2 'variations on orange'
   3 'variations on pear'.
compute allsame = num1 eq num2 and num1 eq num3.
value labels allsame
   0 'false'
   1 'true'.
formats num1 to num3 final1 to final3 (f2) allsame (f1).
list.


On 10/24/2011 10:12 AM, elle wrote:

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: 3-variable comparison with True/False flag

David Marso
Administrator
In reply to this post by elle lists
Something like:
COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
                        MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
HTH, David
---
elle lists wrote
Hi all,



I'd really appreciate your help as I can do this in Excel (=Exact) but can't
compose the equivalent in SPSS syntax.  I'd like to compare three string
variables to verify that the content of each variable (individually and
collectively) contains the same information. (The information varies by name
and character length. So for example, Subject 8's three variables may
identify "Pensacola, FL" whereas Subject 42's data lists "Seattle, WA".)

If the content is the same, then "TRUE" (or "1") is displayed in a separate
column; or if the content differs in one or two cells then "FALSE" (or "0")
is displayed.  So the result would look like this below:






ID

VAR1

VAR2

VAR3

VAR4


Subject1

apple

apple

apple

TRUE


Subject2

apple

pear

apple

FALSE


Subject3

pear

apple

pear

FALSE


Subject4

pear

pear

pear

TRUE




Thanks very much for your help.



Elle
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: 3-variable comparison with True/False flag

Art Kendall
In reply to this post by elle lists
There is. Something like might work if there are few variations on spelling.
something like this would handle different lengths and casing if those were the only variations in content that was supposed to be the same.
compute allsame = upcase(rtrim(ltrim(var1))) eq
upcase(rtrim(ltrim(var2))) and upcase(rtrim(ltrim(var1))) eq upcase(rtrim(ltrim(var3))).

However, if the more usual situation you would often need the check after the autorecode to put
PenseCola FL
Pensencola, FLA
Pensacola       FL
Pensacola Florida
Pensecola FL
Pensacolla, FL
. . .
into the same final value.

Art Kendall
Social Research Consultants

On 10/24/2011 12:17 PM, elle wrote:

Dr. Kendall, thank you very much for the speedy response and solution – very efficient and works like a charm.  BTW, I see the string content is recoded to numeric but was wondering if there’s an SPSS function to compare strings-to-strings? 

 

Many thanks!

 

Elle

 

From: Art Kendall [[hidden email]]
Sent: Monday, October 24, 2011 1:48 AM
To: elle
Cc: [hidden email]
Subject: Re: [SPSSX-L] 3-variable comparison with True/False flag

 

Something like the tested syntax below should do what you want.
Pay close attention to how you generate the recode after the autorecode.

Art Kendall
Social Research Consultants

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.
autorecode var1 to var3 /into num1 to num3/group/print.
recode num1 to num3 (1 thru 3=1) (4=2) (5 thru 7 =3) into final1 to final3.
value labels num1 to num3
   1 'variations on apple'
   2 'variations on orange'
   3 'variations on pear'.
compute allsame = num1 eq num2 and num1 eq num3.
value labels allsame
   0 'false'
   1 'true'.
formats num1 to num3 final1 to final3 (f2) allsame (f1).
list.


On 10/24/2011 10:12 AM, elle wrote:

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

===================== 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: 3-variable comparison with True/False flag

Maguin, Eugene
In reply to this post by David Marso
David,

I've never seen or thought of the min and max functions being used with
strings. So, the min function returns the value that occurs first in the
sort order? Always good to learn something new.

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: Monday, October 24, 2011 8:41 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Something like:
COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
                        MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
HTH, David
---

elle lists wrote:

>
> Hi all,
>
>
>
> I'd really appreciate your help as I can do this in Excel (=Exact) but
> can't
> compose the equivalent in SPSS syntax.  I'd like to compare three string
> variables to verify that the content of each variable (individually and
> collectively) contains the same information. (The information varies by
> name
> and character length. So for example, Subject 8's three variables may
> identify "Pensacola, FL" whereas Subject 42's data lists "Seattle, WA".)
>
> If the content is the same, then "TRUE" (or "1") is displayed in a
> separate
> column; or if the content differs in one or two cells then "FALSE" (or
> "0")
> is displayed.  So the result would look like this below:
>
>
>
>
>
>
> ID
>
> VAR1
>
> VAR2
>
> VAR3
>
> VAR4
>
>
> Subject1
>
> apple
>
> apple
>
> apple
>
> TRUE
>
>
> Subject2
>
> apple
>
> pear
>
> apple
>
> FALSE
>
>
> Subject3
>
> pear
>
> apple
>
> pear
>
> FALSE
>
>
> Subject4
>
> pear
>
> pear
>
> pear
>
> TRUE
>
>
>
>
> Thanks very much for your help.
>
>
>
> Elle
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4932396.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: 3-variable comparison with True/False flag

Art Kendall
In reply to this post by Art Kendall
P. S. If something very unusual were to take take place and there were not variations other than the original field length, justification in the field, and casing you could do the comparison on the original variables  or on the variables produced by autorecode.

Art Kendall
Social Research Consultants

On 10/24/2011 9:01 AM, Art Kendall wrote:
There is. Something like might work if there are few variations on spelling.
something like this would handle different lengths and casing if those were the only variations in content that was supposed to be the same.
compute allsame = upcase(rtrim(ltrim(var1))) eq
upcase(rtrim(ltrim(var2))) and upcase(rtrim(ltrim(var1))) eq upcase(rtrim(ltrim(var3))).

However, if the more usual situation you would often need the check after the autorecode to put
PenseCola FL
Pensencola, FLA
Pensacola       FL
Pensacola Florida
Pensecola FL
Pensacolla, FL
. . .
into the same final value.

Art Kendall
Social Research Consultants

On 10/24/2011 12:17 PM, elle wrote:

Dr. Kendall, thank you very much for the speedy response and solution – very efficient and works like a charm.  BTW, I see the string content is recoded to numeric but was wondering if there’s an SPSS function to compare strings-to-strings? 

 

Many thanks!

 

Elle

 

From: Art Kendall [[hidden email]]
Sent: Monday, October 24, 2011 1:48 AM
To: elle
Cc: [hidden email]
Subject: Re: [SPSSX-L] 3-variable comparison with True/False flag

 

Something like the tested syntax below should do what you want.
Pay close attention to how you generate the recode after the autorecode.

Art Kendall
Social Research Consultants

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.
autorecode var1 to var3 /into num1 to num3/group/print.
recode num1 to num3 (1 thru 3=1) (4=2) (5 thru 7 =3) into final1 to final3.
value labels num1 to num3
   1 'variations on apple'
   2 'variations on orange'
   3 'variations on pear'.
compute allsame = num1 eq num2 and num1 eq num3.
value labels allsame
   0 'false'
   1 'true'.
formats num1 to num3 final1 to final3 (f2) allsame (f1).
list.


On 10/24/2011 10:12 AM, elle wrote:

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

===================== 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: 3-variable comparison with True/False flag

elle lists
In reply to this post by David Marso
David,

Thanks so much for your help and syntax.  Could I clarify the syntax,
though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX" are
displayed in red in the Syntax Editor viewer.  Running the syntax generated
this error message (both shown below):

>Error  # 4314 in column 56.  Text: )
>Only one argument was supplied for a function which requires at least two.
>Execution of this command stops.

Thanks again,

Elle

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: Monday, October 24, 2011 2:41 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Something like:
COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
                        MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
HTH, David
---

elle lists wrote:

>
> Hi all,
>
>
>
> I'd really appreciate your help as I can do this in Excel (=Exact) but
> can't compose the equivalent in SPSS syntax.  I'd like to compare
> three string variables to verify that the content of each variable
> (individually and
> collectively) contains the same information. (The information varies
> by name and character length. So for example, Subject 8's three
> variables may identify "Pensacola, FL" whereas Subject 42's data lists
> "Seattle, WA".)
>
> If the content is the same, then "TRUE" (or "1") is displayed in a
> separate column; or if the content differs in one or two cells then
> "FALSE" (or
> "0")
> is displayed.  So the result would look like this below:
>
>
>
>
>
>
> ID
>
> VAR1
>
> VAR2
>
> VAR3
>
> VAR4
>
>
> Subject1
>
> apple
>
> apple
>
> apple
>
> TRUE
>
>
> Subject2
>
> apple
>
> pear
>
> apple
>
> FALSE
>
>
> Subject3
>
> pear
>
> apple
>
> pear
>
> FALSE
>
>
> Subject4
>
> pear
>
> pear
>
> pear
>
> TRUE
>
>
>
>
> Thanks very much for your help.
>
>
>
> Elle
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4932396.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: 3-variable comparison with True/False flag

Bruce Weaver
Administrator
Try this:

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).

The problem was that "var(3)" needed to be "var3)".

Using Art's DATA LIST and David's COMPUTE:

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
formats var4 (f1.0).
list.


elle lists wrote
David,

Thanks so much for your help and syntax.  Could I clarify the syntax,
though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX" are
displayed in red in the Syntax Editor viewer.  Running the syntax generated
this error message (both shown below):

>Error  # 4314 in column 56.  Text: )
>Only one argument was supplied for a function which requires at least two.
>Execution of this command stops.

Thanks again,

Elle

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: Monday, October 24, 2011 2:41 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Something like:
COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
                        MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
HTH, David
---

elle lists wrote:
>
> Hi all,
>
>
>
> I'd really appreciate your help as I can do this in Excel (=Exact) but
> can't compose the equivalent in SPSS syntax.  I'd like to compare
> three string variables to verify that the content of each variable
> (individually and
> collectively) contains the same information. (The information varies
> by name and character length. So for example, Subject 8's three
> variables may identify "Pensacola, FL" whereas Subject 42's data lists
> "Seattle, WA".)
>
> If the content is the same, then "TRUE" (or "1") is displayed in a
> separate column; or if the content differs in one or two cells then
> "FALSE" (or
> "0")
> is displayed.  So the result would look like this below:
>
>
>
>
>
>
> ID
>
> VAR1
>
> VAR2
>
> VAR3
>
> VAR4
>
>
> Subject1
>
> apple
>
> apple
>
> apple
>
> TRUE
>
>
> Subject2
>
> apple
>
> pear
>
> apple
>
> FALSE
>
>
> Subject3
>
> pear
>
> apple
>
> pear
>
> FALSE
>
>
> Subject4
>
> pear
>
> pear
>
> pear
>
> TRUE
>
>
>
>
> Thanks very much for your help.
>
>
>
> Elle
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4932396.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: 3-variable comparison with True/False flag

elle lists
In reply to this post by Art Kendall

Thank you, Dr. Kendall, for the string-to-string comparison syntax in your prior message and your P.S. advice. The syntax worked perfectly, returning a series of “0”s and “1”s in a new column.  Very cool – will check the manual for more info about the individual syntax components. All I need to do is include a Values Label statement to label the two values as “False” or “True”. 

 

Many thanks for your help!

 

Elle

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall
Sent: Monday, October 24, 2011 3:14 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

 

P. S. If something very unusual were to take take place and there were not variations other than the original field length, justification in the field, and casing you could do the comparison on the original variables  or on the variables produced by autorecode.

Art Kendall
Social Research Consultants

On 10/24/2011 9:01 AM, Art Kendall wrote:

There is. Something like might work if there are few variations on spelling.
something like this would handle different lengths and casing if those were the only variations in content that was supposed to be the same.
compute allsame = upcase(rtrim(ltrim(var1))) eq upcase(rtrim(ltrim(var2)))
and upcase(rtrim(ltrim(var1))) eq upcase(rtrim(ltrim(var3))).

However, if the more usual situation you would often need the check after the autorecode to put
PenseCola FL
Pensencola, FLA
Pensacola       FL
Pensacola Florida
Pensecola FL
Pensacolla, FL
. . .
into the same final value.

Art Kendall
Social Research Consultants

On 10/24/2011 12:17 PM, elle wrote:

Dr. Kendall, thank you very much for the speedy response and solution – very efficient and works like a charm.  BTW, I see the string content is recoded to numeric but was wondering if there’s an SPSS function to compare strings-to-strings? 

 

Many thanks!

 

Elle

 

From: Art Kendall [[hidden email]]
Sent: Monday, October 24, 2011 1:48 AM
To: elle
Cc: [hidden email]
Subject: Re: [SPSSX-L] 3-variable comparison with True/False flag

 

Something like the tested syntax below should do what you want.
Pay close attention to how you generate the recode after the autorecode.

Art Kendall
Social Research Consultants

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.
autorecode var1 to var3 /into num1 to num3/group/print.
recode num1 to num3 (1 thru 3=1) (4=2) (5 thru 7 =3) into final1 to final3.
value labels num1 to num3
   1 'variations on apple'
   2 'variations on orange'
   3 'variations on pear'.
compute allsame = num1 eq num2 and num1 eq num3.
value labels allsame
   0 'false'
   1 'true'.
formats num1 to num3 final1 to final3 (f2) allsame (f1).
list.


On 10/24/2011 10:12 AM, elle wrote:

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

===================== 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: 3-variable comparison with True/False flag

David Marso
Administrator
In reply to this post by Bruce Weaver
Thanks for the correction Bruce ;-)

Bruce Weaver wrote
Try this:

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).

The problem was that "var(3)" needed to be "var3)".

Using Art's DATA LIST and David's COMPUTE:

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
formats var4 (f1.0).
list.


elle lists wrote
David,

Thanks so much for your help and syntax.  Could I clarify the syntax,
though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX" are
displayed in red in the Syntax Editor viewer.  Running the syntax generated
this error message (both shown below):

>Error  # 4314 in column 56.  Text: )
>Only one argument was supplied for a function which requires at least two.
>Execution of this command stops.

Thanks again,

Elle

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: Monday, October 24, 2011 2:41 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Something like:
COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
                        MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
HTH, David
---

elle lists wrote:
>
> Hi all,
>
>
>
> I'd really appreciate your help as I can do this in Excel (=Exact) but
> can't compose the equivalent in SPSS syntax.  I'd like to compare
> three string variables to verify that the content of each variable
> (individually and
> collectively) contains the same information. (The information varies
> by name and character length. So for example, Subject 8's three
> variables may identify "Pensacola, FL" whereas Subject 42's data lists
> "Seattle, WA".)
>
> If the content is the same, then "TRUE" (or "1") is displayed in a
> separate column; or if the content differs in one or two cells then
> "FALSE" (or
> "0")
> is displayed.  So the result would look like this below:
>
>
>
>
>
>
> ID
>
> VAR1
>
> VAR2
>
> VAR3
>
> VAR4
>
>
> Subject1
>
> apple
>
> apple
>
> apple
>
> TRUE
>
>
> Subject2
>
> apple
>
> pear
>
> apple
>
> FALSE
>
>
> Subject3
>
> pear
>
> apple
>
> pear
>
> FALSE
>
>
> Subject4
>
> pear
>
> pear
>
> pear
>
> TRUE
>
>
>
>
> Thanks very much for your help.
>
>
>
> Elle
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4932396.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
Bruce Weaver wrote
Try this:

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).

The problem was that "var(3)" needed to be "var3)".

Using Art's DATA LIST and David's COMPUTE:

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
formats var4 (f1.0).
list.


elle lists wrote
David,

Thanks so much for your help and syntax.  Could I clarify the syntax,
though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX" are
displayed in red in the Syntax Editor viewer.  Running the syntax generated
this error message (both shown below):

>Error  # 4314 in column 56.  Text: )
>Only one argument was supplied for a function which requires at least two.
>Execution of this command stops.

Thanks again,

Elle

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: Monday, October 24, 2011 2:41 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Something like:
COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
                        MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
HTH, David
---

elle lists wrote:
>
> Hi all,
>
>
>
> I'd really appreciate your help as I can do this in Excel (=Exact) but
> can't compose the equivalent in SPSS syntax.  I'd like to compare
> three string variables to verify that the content of each variable
> (individually and
> collectively) contains the same information. (The information varies
> by name and character length. So for example, Subject 8's three
> variables may identify "Pensacola, FL" whereas Subject 42's data lists
> "Seattle, WA".)
>
> If the content is the same, then "TRUE" (or "1") is displayed in a
> separate column; or if the content differs in one or two cells then
> "FALSE" (or
> "0")
> is displayed.  So the result would look like this below:
>
>
>
>
>
>
> ID
>
> VAR1
>
> VAR2
>
> VAR3
>
> VAR4
>
>
> Subject1
>
> apple
>
> apple
>
> apple
>
> TRUE
>
>
> Subject2
>
> apple
>
> pear
>
> apple
>
> FALSE
>
>
> Subject3
>
> pear
>
> apple
>
> pear
>
> FALSE
>
>
> Subject4
>
> pear
>
> pear
>
> pear
>
> TRUE
>
>
>
>
> Thanks very much for your help.
>
>
>
> Elle
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4932396.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: 3-variable comparison with True/False flag

Art Kendall
In reply to this post by elle lists
You're welcome.

Art

On 10/24/2011 6:22 PM, elle wrote:

Thank you, Dr. Kendall, for the string-to-string comparison syntax in your prior message and your P.S. advice. The syntax worked perfectly, returning a series of “0”s and “1”s in a new column.  Very cool – will check the manual for more info about the individual syntax components. All I need to do is include a Values Label statement to label the two values as “False” or “True”. 

 

Many thanks for your help!

 

Elle

 

 

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Art Kendall
Sent: Monday, October 24, 2011 3:14 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

 

P. S. If something very unusual were to take take place and there were not variations other than the original field length, justification in the field, and casing you could do the comparison on the original variables  or on the variables produced by autorecode.

Art Kendall
Social Research Consultants

On 10/24/2011 9:01 AM, Art Kendall wrote:

There is. Something like might work if there are few variations on spelling.
something like this would handle different lengths and casing if those were the only variations in content that was supposed to be the same.
compute allsame = upcase(rtrim(ltrim(var1))) eq upcase(rtrim(ltrim(var2)))
and upcase(rtrim(ltrim(var1))) eq upcase(rtrim(ltrim(var3))).

However, if the more usual situation you would often need the check after the autorecode to put
PenseCola FL
Pensencola, FLA
Pensacola       FL
Pensacola Florida
Pensecola FL
Pensacolla, FL
. . .
into the same final value.

Art Kendall
Social Research Consultants

On 10/24/2011 12:17 PM, elle wrote:

Dr. Kendall, thank you very much for the speedy response and solution – very efficient and works like a charm.  BTW, I see the string content is recoded to numeric but was wondering if there’s an SPSS function to compare strings-to-strings? 

 

Many thanks!

 

Elle

 

From: Art Kendall [[hidden email]]
Sent: Monday, October 24, 2011 1:48 AM
To: elle
Cc: [hidden email]
Subject: Re: [SPSSX-L] 3-variable comparison with True/False flag

 

Something like the tested syntax below should do what you want.
Pay close attention to how you generate the recode after the autorecode.

Art Kendall
Social Research Consultants

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.
autorecode var1 to var3 /into num1 to num3/group/print.
recode num1 to num3 (1 thru 3=1) (4=2) (5 thru 7 =3) into final1 to final3.
value labels num1 to num3
   1 'variations on apple'
   2 'variations on orange'
   3 'variations on pear'.
compute allsame = num1 eq num2 and num1 eq num3.
value labels allsame
   0 'false'
   1 'true'.
formats num1 to num3 final1 to final3 (f2) allsame (f1).
list.


On 10/24/2011 10:12 AM, elle wrote:

Hi all,

 

I’d really appreciate your help as I can do this in Excel (=Exact) but can’t compose the equivalent in SPSS syntax.  I’d like to compare three string variables to verify that the content of each variable (individually and collectively) contains the same information. (The information varies by name and character length. So for example, Subject 8’s three variables may identify “Pensacola, FL” whereas Subject 42’s data lists “Seattle, WA”.)

If the content is the same, then “TRUE” (or “1”) is displayed in a separate column; or if the content differs in one or two cells then “FALSE” (or “0”) is displayed.  So the result would look like this below:

 

 

ID

VAR1

VAR2

VAR3

VAR4

Subject1

apple

apple

apple

TRUE

Subject2

apple

pear

apple

FALSE

Subject3

pear

apple

pear

FALSE

Subject4

pear

pear

pear

TRUE

 


Thanks very much for your help.

 

Elle

 

 

 

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

===================== 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: 3-variable comparison with True/False flag

elle lists
In reply to this post by Bruce Weaver
Bruce Weaver,

Thank you for the information and thanks again to David Marso for the
syntax.  The syntax now runs fine in comparing the three string variables
and returning "0" or "1" in a new column. May I ask for clarification on the
Values Label statement as it doesn't seem to label the results as either
TRUE or FALSE.  Upon checking the Variable View "Values"  field  just this
was displayed:  0=""

Thank you both for your help.

Elle

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Monday, October 24, 2011 11:42 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Try this:

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).

The problem was that "var(3)" needed to be "var3)".

Using Art's DATA LIST and David's COMPUTE:

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
formats var4 (f1.0).
list.



elle lists wrote:

>
> David,
>
> Thanks so much for your help and syntax.  Could I clarify the syntax,
> though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX"
> are
> displayed in red in the Syntax Editor viewer.  Running the syntax
> generated this error message (both shown below):
>
>>Error  # 4314 in column 56.  Text: )
>>Only one argument was supplied for a function which requires at least two.
>>Execution of this command stops.
>
> Thanks again,
>
> Elle
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@.UGA] On Behalf Of David
> Marso
> Sent: Monday, October 24, 2011 2:41 AM
> To: SPSSX-L@.UGA
> Subject: Re: 3-variable comparison with True/False flag
>
> Something like:
> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
>                         MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
> VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
> HTH, David
> ---
>
> elle lists wrote:
>>
>> Hi all,
>>
>>
>>
>> I'd really appreciate your help as I can do this in Excel (=Exact)
>> but can't compose the equivalent in SPSS syntax.  I'd like to compare
>> three string variables to verify that the content of each variable
>> (individually and
>> collectively) contains the same information. (The information varies
>> by name and character length. So for example, Subject 8's three
>> variables may identify "Pensacola, FL" whereas Subject 42's data
>> lists "Seattle, WA".)
>>
>> If the content is the same, then "TRUE" (or "1") is displayed in a
>> separate column; or if the content differs in one or two cells then
>> "FALSE" (or
>> "0")
>> is displayed.  So the result would look like this below:
>>
>>
>>
>>
>>
>>
>> ID
>>
>> VAR1
>>
>> VAR2
>>
>> VAR3
>>
>> VAR4
>>
>>
>> Subject1
>>
>> apple
>>
>> apple
>>
>> apple
>>
>> TRUE
>>
>>
>> Subject2
>>
>> apple
>>
>> pear
>>
>> apple
>>
>> FALSE
>>
>>
>> Subject3
>>
>> pear
>>
>> apple
>>
>> pear
>>
>> FALSE
>>
>>
>> Subject4
>>
>> pear
>>
>> pear
>>
>> pear
>>
>> TRUE
>>
>>
>>
>>
>> Thanks very much for your help.
>>
>>
>>
>> Elle
>>
>
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-wi
> th-Tru
> e-False-flag-tp4932003p4932396.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@.UGA (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
> LISTSERV@.UGA (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
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4934291.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: 3-variable comparison with True/False flag

John F Hall
Looks as if you haven't inserted the labels.  You need to amend your command
to read:

val lab var4 0 'False' 1 'True' .


John F Hall

[hidden email]
www.surveyresearch.weebly.com





-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
elle
Sent: 25 October 2011 02:52
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Bruce Weaver,

Thank you for the information and thanks again to David Marso for the
syntax.  The syntax now runs fine in comparing the three string variables
and returning "0" or "1" in a new column. May I ask for clarification on the
Values Label statement as it doesn't seem to label the results as either
TRUE or FALSE.  Upon checking the Variable View "Values"  field  just this
was displayed:  0=""

Thank you both for your help.

Elle

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Monday, October 24, 2011 11:42 AM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

Try this:

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).

The problem was that "var(3)" needed to be "var3)".

Using Art's DATA LIST and David's COMPUTE:

data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
begin data
   1 apple apple apple
   2 apple pear  apple
   3 pear apple pear
   4 pear pear pear
   5 Apple Apple Apple
   6 Apple Pear  Apple
   7 Pear Apple Pear
   8 Pear Pear Pear
   9 APPLE APPLE APPLE
   10 APPLE PEAR  APPLE
   11 PEAR APPLE PEAR
   12 PEAR PEAR PEAR
   13 pear Pear PEAR
   14 APPLE pear Orange
end data.

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
             MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
formats var4 (f1.0).
list.



elle lists wrote:

>
> David,
>
> Thanks so much for your help and syntax.  Could I clarify the syntax,
> though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX"
> are
> displayed in red in the Syntax Editor viewer.  Running the syntax
> generated this error message (both shown below):
>
>>Error  # 4314 in column 56.  Text: )
>>Only one argument was supplied for a function which requires at least two.
>>Execution of this command stops.
>
> Thanks again,
>
> Elle
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@.UGA] On Behalf Of David
> Marso
> Sent: Monday, October 24, 2011 2:41 AM
> To: SPSSX-L@.UGA
> Subject: Re: 3-variable comparison with True/False flag
>
> Something like:
> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
>                         MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
> VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
> HTH, David
> ---
>
> elle lists wrote:
>>
>> Hi all,
>>
>>
>>
>> I'd really appreciate your help as I can do this in Excel (=Exact)
>> but can't compose the equivalent in SPSS syntax.  I'd like to compare
>> three string variables to verify that the content of each variable
>> (individually and
>> collectively) contains the same information. (The information varies
>> by name and character length. So for example, Subject 8's three
>> variables may identify "Pensacola, FL" whereas Subject 42's data
>> lists "Seattle, WA".)
>>
>> If the content is the same, then "TRUE" (or "1") is displayed in a
>> separate column; or if the content differs in one or two cells then
>> "FALSE" (or
>> "0")
>> is displayed.  So the result would look like this below:
>>
>>
>>
>>
>>
>>
>> ID
>>
>> VAR1
>>
>> VAR2
>>
>> VAR3
>>
>> VAR4
>>
>>
>> Subject1
>>
>> apple
>>
>> apple
>>
>> apple
>>
>> TRUE
>>
>>
>> Subject2
>>
>> apple
>>
>> pear
>>
>> apple
>>
>> FALSE
>>
>>
>> Subject3
>>
>> pear
>>
>> apple
>>
>> pear
>>
>> FALSE
>>
>>
>> Subject4
>>
>> pear
>>
>> pear
>>
>> pear
>>
>> TRUE
>>
>>
>>
>>
>> Thanks very much for your help.
>>
>>
>>
>> Elle
>>
>
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-wi
> th-Tru
> e-False-flag-tp4932003p4932396.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@.UGA (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
> LISTSERV@.UGA (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
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
e-False-flag-tp4932003p4934291.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

=====================
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: 3-variable comparison with True/False flag

David Marso
Administrator
In reply to this post by elle lists
You are welcome!
Please post the EXACT syntax you are running!!!
Very difficult/impossible to diagnose anything without this.
Perhaps you are missing a period (.) after the COMPUTE or are not
running all of the code.
HTH, David

On Mon, Oct 24, 2011 at 9:02 PM, elle lists [via SPSSX Discussion]
<[hidden email]> wrote:

> Bruce Weaver,
>
> Thank you for the information and thanks again to David Marso for the
> syntax.  The syntax now runs fine in comparing the three string variables
> and returning "0" or "1" in a new column. May I ask for clarification on the
> Values Label statement as it doesn't seem to label the results as either
> TRUE or FALSE.  Upon checking the Variable View "Values"  field  just this
> was displayed:  0=""
>
> Thank you both for your help.
>
> Elle
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Bruce Weaver
> Sent: Monday, October 24, 2011 11:42 AM
> To: [hidden email]
> Subject: Re: 3-variable comparison with True/False flag
>
> Try this:
>
> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
>              MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
>
> The problem was that "var(3)" needed to be "var3)".
>
> Using Art's DATA LIST and David's COMPUTE:
>
> data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
> begin data
>    1 apple apple apple
>    2 apple pear  apple
>    3 pear apple pear
>    4 pear pear pear
>    5 Apple Apple Apple
>    6 Apple Pear  Apple
>    7 Pear Apple Pear
>    8 Pear Pear Pear
>    9 APPLE APPLE APPLE
>    10 APPLE PEAR  APPLE
>    11 PEAR APPLE PEAR
>    12 PEAR PEAR PEAR
>    13 pear Pear PEAR
>    14 APPLE pear Orange
> end data.
>
> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
>              MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
> VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
> formats var4 (f1.0).
> list.
>
>
>
> elle lists wrote:
>>
>> David,
>>
>> Thanks so much for your help and syntax.  Could I clarify the syntax,
>> though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX"
>> are
>> displayed in red in the Syntax Editor viewer.  Running the syntax
>> generated this error message (both shown below):
>>
>>>Error  # 4314 in column 56.  Text: )
>>>Only one argument was supplied for a function which requires at least two.
>>>Execution of this command stops.
>>
>> Thanks again,
>>
>> Elle
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:SPSSX-L@.UGA] On Behalf Of David
>> Marso
>> Sent: Monday, October 24, 2011 2:41 AM
>> To: SPSSX-L@.UGA
>> Subject: Re: 3-variable comparison with True/False flag
>>
>> Something like:
>> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
>>                         MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
>> VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
>> HTH, David
>> ---
>>
>> elle lists wrote:
>>>
>>> Hi all,
>>>
>>>
>>>
>>> I'd really appreciate your help as I can do this in Excel (=Exact)
>>> but can't compose the equivalent in SPSS syntax.  I'd like to compare
>>> three string variables to verify that the content of each variable
>>> (individually and
>>> collectively) contains the same information. (The information varies
>>> by name and character length. So for example, Subject 8's three
>>> variables may identify "Pensacola, FL" whereas Subject 42's data
>>> lists "Seattle, WA".)
>>>
>>> If the content is the same, then "TRUE" (or "1") is displayed in a
>>> separate column; or if the content differs in one or two cells then
>>> "FALSE" (or
>>> "0")
>>> is displayed.  So the result would look like this below:
>>>
>>>
>>>
>>>
>>>
>>>
>>> ID
>>>
>>> VAR1
>>>
>>> VAR2
>>>
>>> VAR3
>>>
>>> VAR4
>>>
>>>
>>> Subject1
>>>
>>> apple
>>>
>>> apple
>>>
>>> apple
>>>
>>> TRUE
>>>
>>>
>>> Subject2
>>>
>>> apple
>>>
>>> pear
>>>
>>> apple
>>>
>>> FALSE
>>>
>>>
>>> Subject3
>>>
>>> pear
>>>
>>> apple
>>>
>>> pear
>>>
>>> FALSE
>>>
>>>
>>> Subject4
>>>
>>> pear
>>>
>>> pear
>>>
>>> pear
>>>
>>> TRUE
>>>
>>>
>>>
>>>
>>> Thanks very much for your help.
>>>
>>>
>>>
>>> Elle
>>>
>>
>>
>> --
>> View this message in context:
>> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-wi
>> th-Tru
>> e-False-flag-tp4932003p4932396.html
>> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>> LISTSERV@.UGA (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
>> LISTSERV@.UGA (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
>>
>
> -----
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
> e-False-flag-tp4932003p4934291.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-True-False-flag-tp4932003p4934724.html
> To unsubscribe from 3-variable comparison with True/False flag, click here.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: 3-variable comparison with True/False flag

elle lists

Thank you, David, for your reply. After a third cup of coffee, I realized I made an idiotic mistake by not running frequencies so please disregard my prior question concerning the value labels line not generating the TRUE or FALSE result. Your syntax (below) including the value labels command line runs perfectly.  Don’t know what I was thinking at the time but I obviously wasn’t. ;)

 

COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ

MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).

VALUE LABELS var4 0 'FALSE' 1 'TRUE' .

formats var4 (f1.0).

list.

 

Very sorry, David, for my mistake.  Thanks very much for your help and reminder about including the syntax in question when posting to the list serve.

 

Elle

 

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Monday, October 24, 2011 4:34 PM
To: [hidden email]
Subject: Re: 3-variable comparison with True/False flag

 

You are welcome!
Please post the EXACT syntax you are running!!!
Very difficult/impossible to diagnose anything without this.
Perhaps you are missing a period (.) after the COMPUTE or are not
running all of the code.
HTH, David

On Mon, Oct 24, 2011 at 9:02 PM, elle lists [via SPSSX Discussion]
<[hidden email]> wrote:


> Bruce Weaver,
>
> Thank you for the information and thanks again to David Marso for the
> syntax.  The syntax now runs fine in comparing the three string variables
> and returning "0" or "1" in a new column. May I ask for clarification on the
> Values Label statement as it doesn't seem to label the results as either
> TRUE or FALSE.  Upon checking the Variable View "Values"  field  just this
> was displayed:  0=""
>
> Thank you both for your help.
>
> Elle
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Bruce Weaver
> Sent: Monday, October 24, 2011 11:42 AM
> To: [hidden email]
> Subject: Re: 3-variable comparison with True/False flag
>
> Try this:
>
> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
>              MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
>
> The problem was that "var(3)" needed to be "var3)".
>
> Using Art's DATA LIST and David's COMPUTE:
>
> data list list /subject (f3) var1 (a10) var2(a11)var3(a12).
> begin data
>    1 apple apple apple
>    2 apple pear  apple
>    3 pear apple pear
>    4 pear pear pear
>    5 Apple Apple Apple
>    6 Apple Pear  Apple
>    7 Pear Apple Pear
>    8 Pear Pear Pear
>    9 APPLE APPLE APPLE
>    10 APPLE PEAR  APPLE
>    11 PEAR APPLE PEAR
>    12 PEAR PEAR PEAR
>    13 pear Pear PEAR
>    14 APPLE pear Orange
> end data.
>
> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var3)) EQ
>              MAX(UPCASE(var1),UPCASE(var2),UPCASE(var3)).
> VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
> formats var4 (f1.0).
> list.
>
>
>
> elle lists wrote:
>>
>> David,
>>
>> Thanks so much for your help and syntax.  Could I clarify the syntax,
>> though, as "COMPUTE" and the first parenthesis following "MIN" and "MAX"
>> are
>> displayed in red in the Syntax Editor viewer.  Running the syntax
>> generated this error message (both shown below):
>>
>>>Error  # 4314 in column 56.  Text: )
>>>Only one argument was supplied for a function which requires at least two.
>>>Execution of this command stops.
>>
>> Thanks again,
>>
>> Elle
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [hidden email] On Behalf Of David
>> Marso
>> Sent: Monday, October 24, 2011 2:41 AM
>> To: [hidden email]
>> Subject: Re: 3-variable comparison with True/False flag
>>
>> Something like:
>> COMPUTE var4=MIN(UPCASE(var1),UPCASE(var2),UPCASE(var(3)) EQ
>>                         MAX(UPCASE(var1),UPCASE(var2),UPCASE(var(3))
>> VALUE LABELS var4 0 "FALSE" 1 "TRUE" .
>> HTH, David
>> ---
>>
>> elle lists wrote:
>>>
>>> Hi all,
>>>
>>>
>>>
>>> I'd really appreciate your help as I can do this in Excel (=Exact)
>>> but can't compose the equivalent in SPSS syntax.  I'd like to compare
>>> three string variables to verify that the content of each variable
>>> (individually and
>>> collectively) contains the same information. (The information varies
>>> by name and character length. So for example, Subject 8's three
>>> variables may identify "Pensacola, FL" whereas Subject 42's data
>>> lists "Seattle, WA".)
>>>
>>> If the content is the same, then "TRUE" (or "1") is displayed in a
>>> separate column; or if the content differs in one or two cells then
>>> "FALSE" (or
>>> "0")
>>> is displayed.  So the result would look like this below:
>>>
>>>
>>>
>>>
>>>
>>>
>>> ID
>>>
>>> VAR1
>>>
>>> VAR2
>>>
>>> VAR3
>>>
>>> VAR4
>>>
>>>
>>> Subject1
>>>
>>> apple
>>>
>>> apple
>>>
>>> apple
>>>
>>> TRUE
>>>
>>>
>>> Subject2
>>>
>>> apple
>>>
>>> pear
>>>
>>> apple
>>>
>>> FALSE
>>>
>>>
>>> Subject3
>>>
>>> pear
>>>
>>> apple
>>>
>>> pear
>>>
>>> FALSE
>>>
>>>
>>> Subject4
>>>
>>> pear
>>>
>>> pear
>>>
>>> pear
>>>
>>> TRUE
>>>
>>>
>>>
>>>
>>> Thanks very much for your help.
>>>
>>>
>>>
>>> Elle
>>>
>>
>>
>> --
>> View this message in context:
>> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-wi
>> th-Tru
>> e-False-flag-tp4932003p4932396.html
>> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>
>> =====================
>> 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
>>
>
> -----
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-Tru
> e-False-flag-tp4932003p4934291.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://spssx-discussion.1045642.n5.nabble.com/3-variable-comparison-with-True-False-flag-tp4932003p4934724.html
> To unsubscribe from 3-variable comparison with True/False flag, click here.

 


View this message in context: Re: 3-variable comparison with True/False flag

Sent from the SPSSX Discussion mailing list archive at Nabble.com.