|
I would like to create a new variable based on the maximum value from a list of variables. I have ten continuous variables with a value for each case. For each case I would like the name of the variable that has the highest value in each case. For example, for id 001 the new value in the new variable would be var1. I am receiving eror 4285 is "v1 is not defined by a previous command"
DATA LIST /id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 begin data. 001 100 0 0 1 50 50 10 30 20 13
002 500 0 0 0 0 10 50 25 10 10 003 200 0 0 0 0 0 20 100 100 0 end data. COMPUTE MX=MAX (v1 to v10). DO REPEAT test=v1 to v10/literal="v1", "v2", "v3", "v4", "v5", "v6", "v7",
"v8", "v9", "v10". IF (MX=test) newVar= literal. END REPEAT. EXECUTE. This email may contain confidential information for the sole use of the intended recipient(s). If you are not an intended recipient, please notify the sender and delete all copies immediately. |
|
Administrator
|
Peter,
Please check your variable names! David
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?" |
|
Administrator
|
You should also declare the STRING variable to hold the value.
Also, in the case of ties, note the result will be the last variable in the list matching Max.
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?" |
|
In reply to this post by David Marso
Yes, these are for illustrative purposes only. I see that they are correct in my file. On Tue, Mar 4, 2014 at 1:08 PM, David Marso <[hidden email]> wrote: Peter, This email may contain confidential information for the sole use of the intended recipient(s). If you are not an intended recipient, please notify the sender and delete all copies immediately. |
|
In reply to this post by David Marso
Updated COMPUTE MX=MAX(v1 to v10). DO REPEAT test=v1 to v10/literal="v1", "v2", "v3", "v4", "v5", "v6", "v7",
"v8", "v9", "v10". IF (MX=test) newVar(A3)= literal (A3). END REPEAT. EXECUTE.
On Tue, Mar 4, 2014 at 1:11 PM, David Marso <[hidden email]> wrote: You should also declare the STRING variable to hold the value. This email may contain confidential information for the sole use of the intended recipient(s). If you are not an intended recipient, please notify the sender and delete all copies immediately. |
|
I believe the issue is that: COMPUTE MX=MAX(v1 to v10). Should be: COMPUTE MX=MAX(var1 to var10). Based on your data example. From: SPSSX(r) Discussion [mailto:[hidden email]]
On Behalf Of Peter Spangler Updated COMPUTE MX=MAX(v1 to v10). DO REPEAT test=v1 to v10/literal="v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10". IF (MX=test) newVar(A3)= literal (A3). END REPEAT. EXECUTE. On Tue, Mar 4, 2014 at 1:11 PM, David Marso <[hidden email]> wrote: You should also declare the STRING variable to hold the value. > Peter, View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Select-variable-name-with-max-value-tp5724725p5724727.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.
This correspondence contains proprietary information some or all of which may be legally privileged; it is for the intended recipient only. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this correspondence and completely dispose of the correspondence immediately. Please notify the sender if you have received this email in error. NOTE: Messages to or from the State of Connecticut domain may be subject to the Freedom of Information statutes and regulations. |
|
Administrator
|
In reply to this post by pspangler1
"IF (MX=test) newVar(A3)= literal (A3)."
Peter, you can't just make up syntax that you think might/should work. I directed you to look up STRING command in the FM! In fact, read up in the manual about string variables period. Trying to teach you how to fish rather than just tossing one on the plate for you.
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?" |
|
Thank you, David. I'm on to the FM(!) for STRING. On Wed, Mar 5, 2014 at 8:15 AM, David Marso <[hidden email]> wrote:
This email may contain confidential information for the sole use of the intended recipient(s). If you are not an intended recipient, please notify the sender and delete all copies immediately. |
|
In reply to this post by pspangler1
At 02:50 PM 3/4/2014, Peter Spangler wrote:
>I would like to create a new variable based on the maximum value >from a list of variables. I have ten continuous variables with a >value for each case. For each case I would like the name of the >variable that has the highest value in each case. Peter, you asked precisely this question back in September(1), and it was solved then. I'll repeat the solution that I posted on 10 Sep 2013(2), updated to use your new example data: |-----------------------------|---------------------------| |Output Created |05-MAR-2014 12:04:05 | |-----------------------------|---------------------------| [Input] id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 1 100 0 0 1 50 50 10 30 20 13 2 500 0 0 0 0 10 50 25 10 10 3 200 0 0 0 0 0 20 100 100 0 Number of cases read: 3 Number of cases listed: 3 DATASET COPY Unroll. DATASET ACTIVATE Unroll WINDOW=FRONT. VARSTOCASES /MAKE Value FROM var1 TO var10 /INDEX = Variable(Value) /KEEP = id /NULL = KEEP. Variables to Cases |-----------------------------|---------------------------| |Output Created |05-MAR-2014 12:04:05 | |-----------------------------|---------------------------| [Unroll] Generated Variables |--------|------| |Name |Label | |--------|------| |Variable|<none>| |Value |<none>| |--------|------| Processing Statistics |-------------|--| |Variables In |11| |Variables Out|3 | |-------------|--| LIST. List |-----------------------------|---------------------------| |Output Created |05-MAR-2014 12:04:05 | |-----------------------------|---------------------------| [Unroll] id Variable Value [listing suppressed] Number of cases read: 30 Number of cases listed: 30 SORT CASES BY ID (A) Value (D). AGGREGATE OUTFILE=* /BREAK=ID /HiName 'Variable with largest value' = FIRST(Variable) /HiValue 'Highest value encountered' = FIRST(Value). DATASET NAME Biggest WINDOW=FRONT. LIST. List |-----------------------------|---------------------------| |Output Created |05-MAR-2014 12:04:06 | |-----------------------------|---------------------------| [Biggest] id HiName HiValue 1 var1 100 2 var1 500 3 var1 200 Number of cases read: 3 Number of cases listed: 3 * Now it's simple to add these values to the original file:. MATCH FILES /FILE =Input /TABLE=Biggest /BY ID. DATASET NAME Final WINDOW=FRONT. LIST. List |-----------------------------|---------------------------| |Output Created |05-MAR-2014 12:04:06 | |-----------------------------|---------------------------| [Final] id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 HiName HiValue 1 100 0 0 1 50 50 10 30 20 13 var1 100 2 500 0 0 0 0 10 50 25 10 10 var1 500 3 200 0 0 0 0 0 20 100 100 0 var1 200 Number of cases read: 3 Number of cases listed: 3 ============================= (1) Original question Date: Tue, 10 Sep 2013 13:47:13 -0700 From: Peter Spangler <[hidden email]> Subject: select variable name with greatest value To: [hidden email] (2) Previously posted solution Date: Tue, 10 Sep 2013 21:30:17 -0400 From: Richard Ristow <[hidden email]> Subject: Re: select variable name with greatest value To: [hidden email] ============================= APPENDIX: Test data, and code (WRR: Not saved separately) ============================= DATA LIST LIST /id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 (N3, 10F4). begin data. 001 100 0 0 1 50 50 10 30 20 13 002 500 0 0 0 0 10 50 25 10 10 003 200 0 0 0 0 0 20 100 100 0 end data. DATASET NAME Input WINDOW=FRONT. LIST. DATASET COPY Unroll. DATASET ACTIVATE Unroll WINDOW=FRONT. VARSTOCASES /MAKE Value FROM var1 TO var10 /INDEX = Variable(Value) /KEEP = id /NULL = KEEP. LIST. SORT CASES BY ID (A) Value (D). AGGREGATE OUTFILE=* /BREAK=ID /HiName 'Variable with largest value' = FIRST(Variable) /HiValue 'Highest value encountered' = FIRST(Value). DATASET NAME Biggest WINDOW=FRONT. LIST. * Now it's simple to add these values to the original file:. MATCH FILES /FILE =Input /TABLE=Biggest /BY ID. DATASET NAME Final WINDOW=FRONT. LIST. X-ELNK-Received-Info: spv=0; X-ELNK-AV: 0 X-ELNK-Info: sbv=0; sbrc=.0; sbf=bb; sbw=000; > For example, for id 001 the new value in the new variable would be > var1. I am receiving eror 4285 is "v1 is not defined by a previous command" > >DATA LIST >/id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 >begin data. >001 100 0 0 1 50 50 10 30 20 13 >002 500 0 0 0 0 10 50 25 10 10 >003 200 0 0 0 0 0 20 100 100 0 >end data. > >COMPUTE MX=MAX (v1 to v10). >DO REPEAT test=v1 to v10/literal="v1", "v2", "v3", "v4", "v5", "v6", "v7", >"v8", "v9", "v10". >IF (MX=test) newVar= literal. >END REPEAT. >EXECUTE. > >This email may contain confidential information for the sole use of >the intended recipient(s). If you are not an intended recipient, >please notify the sender and delete all copies immediately. ===================== 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 |
| Free forum by Nabble | Edit this page |
