Hi,
I have a question concerning the count syntax. I have about 50 variables, all can have a code 1, 2 or 3. v1 v2 v3 … v50 1 2 3 1 2 2 3 1 1 1 3 1 Now I made a new variable to count all '2' per row. Is it possible to make a new variable with which I can easily see in which of the 50 variables the code 2 is mentioned? Of course I can filter by the count variable but then have to search through all 50 variables where the '2 s' are. Thank you in advance! ===================== 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 |
Use count. Count newvar= v1 to v50 (2). On Feb 20, 2015 7:20 PM, "claudia" <[hidden email]> wrote:
=====================
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
Hi, |
In reply to this post by emma78
I do not have time to test this but use something like
<analyze><custom tables> ... <paste> to create syntax to create a table with variables as rows and the possible values as columns.
Art Kendall
Social Research Consultants |
Administrator
|
In reply to this post by emma78
Untested: No SPSS on this box (WinBlows 8 updates keep hosing my rig and I haven't installed anything pending the next FUBARed Update!!!). Don't even dare to reboot. Reset the beast to factory something like 8 times in the past month!
STRING two_locations (A200). VECTOR vars=v1 TO v50. LOOP #two_loc=1 TO 50. IF vars(#two_loc)=2 two_locations=CONCAT(RTRIM(two_locations),",",STRING(#two_loc,F2)). END LOOP.
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?" |
Hi David,
thank you, that works! A small addition: In one case I have saved all needed variables in a macro such as !var. Is there a chance that I can I use the vector with this !var? VECTOR vars=v1 TO v4. |
Administrator
|
Note that VECTOR requires the form:
VECTOR v=firstvar TO lastvar and they MUST be contiguous. Since they very well might not be lets assume your !var looks like DEFINE !var () a b c d e g q w x z !ENDDEFINE . Proceed as follows: COMPUTE #=1. DO REPEAT v = !vars . IF v=2 .......same code as before with concat blah blah blah.... except use # in the STRING function... COMPUTE #=#+1. END REPEAT. ----
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?" |
Ok, I changed it to
IF v=2 two_locations=CONCAT(RTRIM(two_locations),",",STRING(v,F2)). Did I make a mistake? Because now the postion in two_locations isn`t correct any more. I see the code and not the position... |
Administrator
|
Reread my previous reply ;-)
-- IF v=2 two_locations=CONCAT(RTRIM(two_locations),",",STRING(#,F2)).
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 emma78
At 08:50 AM 2/20/2015, claudia wrote:
>I have about 50 variables, all can have a code 1, 2 or 3. > >v1 v2 v3 v50 >1 2 3 1 >2 2 3 1 >1 1 3 1 > >Is it possible to make a new variable with which >I can easily see in which of the 50 variables the code 2 is mentioned? Here's an alternative approach, illustrated with ten variables and ten cases. In it, . The variables you're counting don't have to be contiguous (though the VARSTOCASES is easier to code if they are) . The variable names don't need to be given explicitly, except in the VARSTOCASES. They don't have to have the form "Root-suffix". . I've left the names of variables whose value is "2" in separate variables, but it's easy to combine them into a single variable if you want to. |-----------------------------|----------------------------| |Output Created |22-FEB-2015 18:57:04 | |-----------------------------|----------------------------| [TestData] CaseID V01 V02 V03 V04 V05 V06 V07 V08 V09 V10 001 3 1 1 3 2 1 2 3 2 1 002 3 1 1 1 1 2 1 1 2 1 003 1 3 3 2 3 1 3 1 1 2 004 1 1 1 2 2 1 3 2 2 2 005 3 1 2 1 2 3 1 3 3 1 006 1 1 1 1 3 3 1 1 1 3 007 1 1 3 1 1 1 2 1 1 1 008 2 2 3 2 1 3 1 1 3 3 009 1 2 2 1 1 1 1 1 1 3 010 1 1 3 1 2 1 1 1 1 3 Number of cases read: 10 Number of cases listed: 10 DATASET COPY Restruct. DATASET ACTIVATE Restruct WINDOW=FRONT. VARSTOCASES /MAKE Value FROM V01 V02 V03 V04 V05 V06 V07 V08 V09 V10 /INDEX = Name(Value) /KEEP = CaseID /NULL = DROP. Variables to Cases |-----------------------------|----------------------------| |Output Created |22-FEB-2015 18:57:04 | |-----------------------------|----------------------------| [Restruct] Generated Variables |-----|------| |Name |Label | |-----|------| |Name |<none>| |Value|<none>| |-----|------| Processing Statistics |-------------|--| |Variables In |11| |Variables Out|3 | |-------------|--| SELECT IF Value EQ 2. CASESTOVARS /ID = CaseID /GROUPBY = VARIABLE /DROP = Value /RENAME Name=VN. Cases to Variables |-----------------------------|----------------------------| |Output Created |22-FEB-2015 18:57:05 | |-----------------------------|----------------------------| [Restruct] Generated Variables |---------|------| |Original |Result| |Variabl |------| |e |Name | |-------|-|------| |Name |1|VN.1 | | |2|VN.2 | | |3|VN.3 | | |4|VN.4 | | |5|VN.5 | |-------|-|------| Processing Statistics |---------------|---| |Cases In |21 | |Cases Out |9 | |---------------|---| |Cases In/Cases |2.3| |Out | | |---------------|---| |Variables In |3 | |---------------|---| |Variables Out |6 | |---------------|---| |Index Values |5 | |---------------|---| MATCH FILES /FILE=TestData /FILE=Restruct /BY CaseID. DATASET NAME Final WINDOW=FRONT. LIST. List |-----------------------------|----------------------------| |Output Created |22-FEB-2015 18:57:05 | |-----------------------------|----------------------------| [Final] CaseID V01 V02 V03 V04 V05 V06 V07 V08 V09 V10 VN.1 VN.2 VN.3 VN.4 VN.5 001 3 1 1 3 2 1 2 3 2 1 V05 V07 V09 002 3 1 1 1 1 2 1 1 2 1 V06 V09 003 1 3 3 2 3 1 3 1 1 2 V04 V10 004 1 1 1 2 2 1 3 2 2 2 V04 V05 V08 V09 V10 005 3 1 2 1 2 3 1 3 3 1 V03 V05 006 1 1 1 1 3 3 1 1 1 3 007 1 1 3 1 1 1 2 1 1 1 V07 008 2 2 3 2 1 3 1 1 3 3 V01 V02 V04 009 1 2 2 1 1 1 1 1 1 3 V02 V03 010 1 1 3 1 2 1 1 1 1 3 V05 Number of cases read: 10 Number of cases listed: 10 ================================ APPENDIX: Test data and all code ================================ * C:\Documents and Settings\Richard\My Documents . * \Technical\spssx-l\Z-2015\ . * 2015-02-20 claudia-Count.SPS . * In response to posting . * Date: Fri, 20 Feb 2015 08:50:44 -0500 . * From: claudia <[hidden email]> . * Subject: Count . * To: [hidden email] . * "I have about 50 variables, all can have a code 1, 2 or 3. . * . * v1 v2 v3 v50 . * 1 2 3 1 . * 2 2 3 1 . * 1 1 3 1 . * . * Is it possible to make a new variable with which I can easily . * see in which of the 50 variables the code 2 is mentioned?" . * ................................................................ . * ................. Test data .................... . SET RNG = MT /* 'Mersenne twister' random number generator */ . SET MTINDEX = 6436 /* Providence, RI telephone book */ . * 10 cases, 10 variables, value=2 with probability 0.2 . NEW FILE. INPUT PROGRAM. . NUMERIC CaseID (N3). . NUMERIC #Uniform (F10.7). . NUMERIC #Coice (F2). . NUMERIC V01 TO V10 (F2). . VECTOR V=V01 TO V10. . LOOP CaseID = 1 TO 10. . LOOP #Idx = 1 TO 10. . COMPUTE #Uniform=RV.UNIFORM(0,1). . RECODE #Uniform (0 THRU 0.5 = 1) (0.5 THRU 0.7 = 2) (0.7 THRU 1 = 3) INTO #Choice. . COMPUTE V(#idx) = #Choice. . END LOOP. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME TestData WINDOW=FRONT. . /**/ LIST /*-*/. * ................ Post after this point ..................... . DATASET COPY Restruct. DATASET ACTIVATE Restruct WINDOW=FRONT. VARSTOCASES /MAKE Value FROM V01 V02 V03 V04 V05 V06 V07 V08 V09 V10 /INDEX = Name(Value) /KEEP = CaseID /NULL = DROP. SELECT IF Value EQ 2. CASESTOVARS /ID = CaseID /GROUPBY = VARIABLE /DROP = Value /RENAME Name=VN. VARIABLE WIDTH VN.1 TO VN.5 (4). MATCH FILES /FILE=TestData /FILE=Restruct /BY CaseID. DATASET NAME Final WINDOW=FRONT. LIST. ===================== 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 |