|
Dear List,
I'm trying to create a new variable based on eight STRING variables. My syntax is below that works. Is there a more efficient way to write the syntax to create the variable? Something that doesn't repeat the IF statement over and over again? COMPUTE AWARD = 0. IF (AWARTYP1 = 'GP') AWARD =1. IF (AWARTYP2 = 'GP') AWARD =1. IF (AWARTYP3 = 'GP') AWARD =1. IF (AWARTYP4 = 'GP') AWARD =1. IF (AWARTYP5 = 'GP') AWARD =1. IF (AWARTYP6 = 'GP') AWARD =1. IF (AWARTYP7 = 'GP') AWARD =1. IF (AWARTYP8 = 'GP') AWARD =1. Execute. Thanks in Advance, Sam SDCCD ===================== 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 the variables are already contiguous try something like this untested
syntax. /compute award = any(awartyp1 to awartyp8,'GP') or //any(awartyp1 to awartyp8,'gp')//. /OR/ //count award = awartyp1 to awartyp8('GP','gp'). recode award (0=0)(1 thru 8=1)(else=copy) into award2./ You can make them contiguous by something like this. /match files file=*/keep = awartyp1, awartyp2, awartyp3, awartyp4, awartyp5, awartyp6, awartyp7, awartyp8, all. / If they are not contiguous you can do something like this. /count award = awartyp1, awartyp2, awartyp3, awartyp4, awartyp5, awartyp6, awartyp7, awartyp8('GP','gp'). recode award (0=0)(1 thru 8=1)(else=copy) into award2. / Art Kendall Social Research Consultants Sam Ballard wrote: > Dear List, > > I'm trying to create a new variable based on eight STRING variables. My > syntax is below that works. Is there a more efficient way to write the > syntax to create the variable? Something that doesn't repeat the IF > statement over and over again? > > COMPUTE AWARD = 0. > IF (AWARTYP1 = 'GP') AWARD =1. > IF (AWARTYP2 = 'GP') AWARD =1. > IF (AWARTYP3 = 'GP') AWARD =1. > IF (AWARTYP4 = 'GP') AWARD =1. > IF (AWARTYP5 = 'GP') AWARD =1. > IF (AWARTYP6 = 'GP') AWARD =1. > IF (AWARTYP7 = 'GP') AWARD =1. > IF (AWARTYP8 = 'GP') AWARD =1. > Execute. > > > Thanks in Advance, > Sam > SDCCD > > ===================== > 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 |
| Free forum by Nabble | Edit this page |
