Dear list,
I have a series of variables (procode1 to procode104) coded 1 thru 9. I would like to compute new variables (code1 to code9) based on whether the original variable had a certain code in it or not. See example below. I have searched the listâs archives but could not figure out a good way of doing this. Can anyone suggest a posting and/or syntax? Any help would be greatly appreciated. Thanks IF (proccode1 =1 or proccode2 = 1 or ⦠proccode104=1) code1=1. IF (proccode1 =2 or proccode2 = 2 or ⦠proccode104=2) code2=1. IF (proccode1 =3 or proccode2 = 3 or ⦠proccode104=3) code3=1. IF (proccode1 =4 or proccode2 = 4 or ⦠proccode104=4) code4=1. IF (proccode1 =5 or proccode2 = 5 or ⦠proccode104=5) code5=1. IF (proccode1 =6 or proccode2 = 6 or ⦠proccode104=6) code6=1. IF (proccode1 =7 or proccode2 = 7 or ⦠proccode104=7) code7=1. IF (proccode1 =8 or proccode2 = 8 or ⦠proccode104=8) code8=1. IF (proccode1 =9 or proccode2 = 9 or ⦠proccode104=9) code9=1. |
I think you may be looking for the "ANY" function.
IF (ANY(1, proccode1 TO proccode104)) code1=1. IF (ANY(2, proccode1 TO proccode104)) code2=1. IF (ANY(3, proccode1 TO proccode104)) code3=1. IF (ANY(4, proccode1 TO proccode104)) code4=1. IF (ANY(5, proccode1 TO proccode104)) code5=1. IF (ANY(6, proccode1 TO proccode104)) code6=1. IF (ANY(7, proccode1 TO proccode104)) code7=1. IF (ANY(8, proccode1 TO proccode104)) code8=1. IF (ANY(9, proccode1 TO proccode104)) code9=1. The first argument of the ANY function is the value you are looking for, and the remaining arguments are the variables in which you are looking for that value. The ANY function can also be used like this: IF (ANY(var1, 1, 2, 3, 5, 7, 11)) flag=1. In this usage, the first argument is the single variable you are examining, and the remaining arguments are the values you are checking for. In this example, the value of "flag" would be set to 1 if the variable var1 were equal to any of the values listed. - James Cantor -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Giuseppina Chiri Sent: Saturday, March 24, 2007 2:15 PM To: [hidden email] Subject: multiple IF statements Dear list, I have a series of variables (procode1 to procode104) coded 1 thru 9. I would like to compute new variables (code1 to code9) based on whether the original variable had a certain code in it or not. See example below. I have searched the listâEUR(tm)s archives but could not figure out a good way of doing this. Can anyone suggest a posting and/or syntax? Any help would be greatly appreciated. Thanks IF (proccode1 =1 or proccode2 = 1 or âEUR¦ proccode104=1) code1=1. IF (proccode1 =2 or proccode2 = 2 or âEUR¦ proccode104=2) code2=1. IF (proccode1 =3 or proccode2 = 3 or âEUR¦ proccode104=3) code3=1. IF (proccode1 =4 or proccode2 = 4 or âEUR¦ proccode104=4) code4=1. IF (proccode1 =5 or proccode2 = 5 or âEUR¦ proccode104=5) code5=1. IF (proccode1 =6 or proccode2 = 6 or âEUR¦ proccode104=6) code6=1. IF (proccode1 =7 or proccode2 = 7 or âEUR¦ proccode104=7) code7=1. IF (proccode1 =8 or proccode2 = 8 or âEUR¦ proccode104=8) code8=1. IF (proccode1 =9 or proccode2 = 9 or âEUR¦ proccode104=9) code9=1. |
Free forum by Nabble | Edit this page |