|
Hi ,
ID ASSOCIATION 1 Basketball 1 Soccer When i use the cases to vars procedure I get the outut below: casestovars /id = id /groupby = variable. ID Association.1 Association.2 1 Basketball Soccer I then use the following syntax: rename variables (asssociation.1 = sport1) (association.2 = sport2) select if (any(association.1, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis') | any(association.2, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis')). I am running a syntax file for different school terms and in some term the number of associations may be greater than 2. Is there any way I can adjust the syntax (specifically, the rename and select statements) to take into account how many associations there are? Thanks, Keval ====================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 |
|
Keval,
Maybe I am missing something but I can't see how one of your syntax statements will work correctly given the prior statement. See below for details. In response to your specific question, I don't think there is an syntax solution for this. (I suspect that using either script or python you could inspect the dictionary and count the number of times 'association' is listed. I can't do this. Somebody else can comment.) Instead, I think you have to determine this number interactively. That said, there are a number of methods for doing so. A frequencies of ID will show the number of records for each id. You could aggregate by id to get a case count that is added to the current dataset (mode=addvariables) and do a frequencies on that variable. After the casestovars is completed, you can look at the dictionary and see how many association variables there are. Lastly, I think the Casestovars command may report something about this but I am not sure. Once you know that number, you could use the Numeric command to create additional variables so that your rename and select if statements are constants. (Again, I'll bet that either script or python could be used to 'fix up' dataset after the casestovars to have a constant number of association variables. However, you still have the problem of deciding on a max number. Again, somebody that knows script or python can comment.) Gene Maguin ID ASSOCIATION 1 Basketball 1 Soccer When i use the cases to vars procedure I get the outut below: casestovars /id = id/groupby = variable. ID Association.1 Association.2 1 Basketball Soccer I then use the following syntax: rename variables (asssociation.1 = sport1) (association.2 = sport2) select if (any(association.1, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis') | any(association.2, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis')). **** This is the problem. Following the rename command, the variables Association.1 and Association.2 no longer exist. So, the select if statement should be giving an error. By the way, why not so the rename prior to the casestovars. I am running a syntax file for different school terms and in some term the number of associations may be greater than 2. Is there any way I can adjust the syntax (specifically, the rename and select statements) to take into account how many associations there are? Thanks, Keval ======= 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 |
|
In reply to this post by Keval Khichadia
At 10:24 AM 12/31/2008, Keval Khichadia wrote (but I'm quoting Gene
Maguin's reformulation): >ID ASSOCIATION >1 Basketball >1 Soccer > >When i use the cases to vars procedure I get the outut below: > casestovars /id = id/groupby = variable. > > >ID Association.1 Association.2 >1 Basketball Soccer > >I then use the following syntax: > >rename variables (asssociation.1 = sport1) (association.2 = sport2) > >select if (any(association.1, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', >'Softball', 'Volleyball', 'Tennis') | >any(association.2, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', >'Volleyball', 'Tennis')). > >>[Gene] Why not do the rename prior to the casestovars? Yes. Or, as part of the CASESTOVARS. >Is there any way I can adjust the syntax (specifically, the rename >and select statements) to take into account how many associations there are? >>[Gene] I don't think there is a syntax solution for this. I suspect >>that using either script or python you could inspect the dictionary >>and count the number of times 'association' is listed. Python is the way to generate code that depends on the data dictionary. BUT, you *can* solve the problem in pure syntax, using the original 'long' orientation of the file, before CASESTOVARS. (You won't be surprised that I write this.) Like the code below. Tested, but the test dataset is too small for a stringent test. |-----------------------------|---------------------------| |Output Created |02-JAN-2009 22:43:35 | |-----------------------------|---------------------------| ID ASSOCIATION 1 Basketball 1 Soccer Number of cases read: 2 Number of cases listed: 2 NUMERIC Take_It (F2). VAR LABEL Take_It "Flag for whether this ID's cases will be kept". COMPUTE Take_It = any(ASSOCIATION, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis'). AGGREGATE OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES /BREAK = ID /Take_It = MAX(Take_It). . /**/ LIST /*-*/. List |-----------------------------|---------------------------| |Output Created |02-JAN-2009 22:43:36 | |-----------------------------|---------------------------| ID ASSOCIATION Take_It 1 Basketball 1 1 Soccer 1 Number of cases read: 2 Number of cases listed: 2 SORT CASES BY ID Take_It . CASESTOVARS /ID = ID Take_It /RENAME ASSOCIATION=SPORT /SEPARATOR = "" /GROUPBY = VARIABLE . Cases to Variables |-----------------------------|---------------------------| |Output Created |02-JAN-2009 22:43:36 | |-----------------------------|---------------------------| Generated Variables |-------------|------| |Original |Result| |Variable |------| | |Name | |-----------|-|------| |ASSOCIATION|1|SPORT1| | |2|SPORT2| |-----------|-|------| Processing Statistics |---------------|---| |Cases In |2 | |Cases Out |1 | |---------------|---| |Cases In/Cases |2.0| |Out | | |---------------|---| |Variables In |3 | |Variables Out |4 | |---------------|---| |Index Values |2 | |---------------|---| LIST. List |-----------------------------|---------------------------| |Output Created |02-JAN-2009 22:43:36 | |-----------------------------|---------------------------| ID Take_It SPORT1 SPORT2 1 1 Basketball Soccer Number of cases read: 1 Number of cases listed: 1 ============================ APPENDIX: Test data and code ============================ DATA LIST LIST/ ID ASSOCIATION (F2, A10). BEGIN DATA 1 Basketball 1 Soccer END DATA. LIST. NUMERIC Take_It (F2). VAR LABEL Take_It "Flag for whether this ID's cases will be kept". COMPUTE Take_It = any(ASSOCIATION, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis'). AGGREGATE OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES /BREAK = ID /Take_It = MAX(Take_It). . /**/ LIST /*-*/. SORT CASES BY ID Take_It . CASESTOVARS /ID = ID Take_It /RENAME ASSOCIATION=SPORT /SEPARATOR = "" /GROUPBY = VARIABLE . 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 |
|
In reply to this post by Keval Khichadia
This problem is far easier to address in the original long data structure than in the wide data structure that casestovars gives. Apply casestovars, if you still need it, after selecting the records showing the selected sports.
Jonathan Fry -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Keval Khichadia Sent: Wednesday, December 31, 2008 9:24 AM To: [hidden email] Subject: cases to vars Hi , ID ASSOCIATION 1 Basketball 1 Soccer When i use the cases to vars procedure I get the outut below: casestovars /id = id /groupby = variable. ID Association.1 Association.2 1 Basketball Soccer I then use the following syntax: rename variables (asssociation.1 = sport1) (association.2 = sport2) select if (any(association.1, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis') | any(association.2, 'Basketball', 'Soccer', 'Golf', 'Lacrosse', 'Softball', 'Volleyball', 'Tennis')). I am running a syntax file for different school terms and in some term the number of associations may be greater than 2. Is there any way I can adjust the syntax (specifically, the rename and select statements) to take into account how many associations there are? Thanks, Keval ======= 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 |
| Free forum by Nabble | Edit this page |
