I need some syntax to create a numeric variable named BakerUser based on
3 non-contiguous variables. All 3 variables contain either a system missing code or a 1 or a zero. If all 3 non-contiguous variables are system missing then BakerUser should be given a value of system missing. If none of the 3 non-contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then BakerUser should be given a value of 0. If any of the 3 non-contiguous variables contain a value of 1 then BakerUser should be given a value of 1. I tried writing this syntax: COMPUTE BakerUser=$sysmis. EXECUTE. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. EXECUTE. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND IF (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. It crashes on the IF command with the following error message: Error#4023 in column 44. Text: IF An expression contains a string of characters followed by a left parenthesis, indicating that the string of characters is a function or vector name, but the characters do not match any existing function or vector. Check the spelling. This command not executed. Any suggestions? I also need some syntax to create a numeric variable named AcmeUser based on the values of 18 contiguous variables named q4a1 to q4a18. All 18 variables are either system missing or they contain either a 1 or a zero. If all 18 contiguous variables are system missing then AcmeUser should be given a value of system missing. If none of the 18 contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then AcmeUser should be given a value of 0. If any of 18 contiguous variables contain a value of 1 then AcmeUser should be given a value of 1. How would I write syntax similar to that noted above where the original variables are contiguous without having to list all eighteen variables. Thanks for your help. |
IF ( code ) and IF (code) is not legal.
Try IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. This will evaluate both brackets and set BakerUser to "0" when both are true. You can use IF ANY(0, q4a1 TO q4a18) AcmeUser = 0. To evaluate a set of contiguous variables. Remember that you could have both 0 and 1 in your set of variables-- SPSS will evaluate the IF statements in order. Marke sure the last statement is one you want to "dominate" the code. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Friday, July 21, 2006 2:37 PM To: [hidden email] Subject: Identify Users Syntax I need some syntax to create a numeric variable named BakerUser based on 3 non-contiguous variables. All 3 variables contain either a system missing code or a 1 or a zero. If all 3 non-contiguous variables are system missing then BakerUser should be given a value of system missing. If none of the 3 non-contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then BakerUser should be given a value of 0. If any of the 3 non-contiguous variables contain a value of 1 then BakerUser should be given a value of 1. I tried writing this syntax: COMPUTE BakerUser=$sysmis. EXECUTE. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. EXECUTE. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND IF (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. It crashes on the IF command with the following error message: Error#4023 in column 44. Text: IF An expression contains a string of characters followed by a left parenthesis, indicating that the string of characters is a function or vector name, but the characters do not match any existing function or vector. Check the spelling. This command not executed. Any suggestions? I also need some syntax to create a numeric variable named AcmeUser based on the values of 18 contiguous variables named q4a1 to q4a18. All 18 variables are either system missing or they contain either a 1 or a zero. If all 18 contiguous variables are system missing then AcmeUser should be given a value of system missing. If none of the 18 contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then AcmeUser should be given a value of 0. If any of 18 contiguous variables contain a value of 1 then AcmeUser should be given a value of 1. How would I write syntax similar to that noted above where the original variables are contiguous without having to list all eighteen variables. Thanks for your help. |
Jim:
Thanks for the advice. I used it to modify the non-contiguous variable syntax and it runs perfectly as follows: COMPUTE BakerUser=$sysmis. EXECUTE. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. EXECUTE. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. However, I'm still having trouble with the contiguous variable code because the first part of the IF line would have to be akin to something like an ALL command instead of an ANY command (if all of the 18 contiguous variables are "not equal" to 1 and any are equal to zero, AcmeUser gets a zero). The code would have to be something like this: COMPUTE AcmeUser=$sysmis. EXECUTE. IF ANY(1,q4a1 TO q4a18) AcmeUser=1. EXECUTE. FORMAT AcmeUser (f1.0). IF ALL (~=1, q4a1 TO q4a18) AND IF ANY(0,q4a1 TO q4a18) AcmeUser=0. EXECUTE. Unfortunately, the IF line of the preceeding code generates this error code: >Error # 4014 in column 4. Text: ALL >SPSS was expecting an expression but encountered the end of the command. >Check the expression for omitted or extra operands, operators, and >parentheses. >This command not executed. Any suggestions? -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marks, Jim Sent: Friday, July 21, 2006 3:03 PM To: [hidden email] Subject: Re: Identify Users Syntax IF ( code ) and IF (code) is not legal. Try IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. This will evaluate both brackets and set BakerUser to "0" when both are true. You can use IF ANY(0, q4a1 TO q4a18) AcmeUser = 0. To evaluate a set of contiguous variables. Remember that you could have both 0 and 1 in your set of variables-- SPSS will evaluate the IF statements in order. Marke sure the last statement is one you want to "dominate" the code. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Friday, July 21, 2006 2:37 PM To: [hidden email] Subject: Identify Users Syntax I need some syntax to create a numeric variable named BakerUser based on 3 non-contiguous variables. All 3 variables contain either a system missing code or a 1 or a zero. If all 3 non-contiguous variables are system missing then BakerUser should be given a value of system missing. If none of the 3 non-contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then BakerUser should be given a value of 0. If any of the 3 non-contiguous variables contain a value of 1 then BakerUser should be given a value of 1. I tried writing this syntax: COMPUTE BakerUser=$sysmis. EXECUTE. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. EXECUTE. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND IF (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. It crashes on the IF command with the following error message: Error#4023 in column 44. Text: IF An expression contains a string of characters followed by a left parenthesis, indicating that the string of characters is a function or vector name, but the characters do not match any existing function or vector. Check the spelling. This command not executed. Any suggestions? I also need some syntax to create a numeric variable named AcmeUser based on the values of 18 contiguous variables named q4a1 to q4a18. All 18 variables are either system missing or they contain either a 1 or a zero. If all 18 contiguous variables are system missing then AcmeUser should be given a value of system missing. If none of the 18 contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then AcmeUser should be given a value of 0. If any of 18 contiguous variables contain a value of 1 then AcmeUser should be given a value of 1. How would I write syntax similar to that noted above where the original variables are contiguous without having to list all eighteen variables. Thanks for your help. |
In reply to this post by Jim Moffitt
Jim:
You can check for the presence of the value "1" in q1 to q18 using NOT ANY ( )-- Something like this: IF ANY(0,q1 TO q18) AND NOT ANY(1,Q1 TO q18) acmeuser = 0. IF ANY(1,q1 TO q18) acmeuser = 1. If the variables are non-contiguous, you can supply a list: IF ANY(1,q1, q2, q5 TO q10, q18) acmeuser = 1. When the variable acmeuser is created by the IF command, all cases are initialed to system missing. If a case does not pass both IF statements, it is left as system missing. (This will include cases with a non-missing value other than 1 or 0.) Note that you can simplify your code by removing the "EXECUTE" commands after each COMPUTE or IF statement: COMPUTE BakerUser=$sysmis. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. SPSS will process all the COMPUTE's and IF's for each case and return the final result in one data pass. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Friday, July 21, 2006 3:52 PM To: [hidden email] Subject: Re: Identify Users Syntax Jim: Thanks for the advice. I used it to modify the non-contiguous variable syntax and it runs perfectly as follows: COMPUTE BakerUser=$sysmis. EXECUTE. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. EXECUTE. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. However, I'm still having trouble with the contiguous variable code because the first part of the IF line would have to be akin to something like an ALL command instead of an ANY command (if all of the 18 contiguous variables are "not equal" to 1 and any are equal to zero, AcmeUser gets a zero). The code would have to be something like this: COMPUTE AcmeUser=$sysmis. EXECUTE. IF ANY(1,q4a1 TO q4a18) AcmeUser=1. EXECUTE. FORMAT AcmeUser (f1.0). IF ALL (~=1, q4a1 TO q4a18) AND IF ANY(0,q4a1 TO q4a18) AcmeUser=0. EXECUTE. Unfortunately, the IF line of the preceeding code generates this error code: >Error # 4014 in column 4. Text: ALL >SPSS was expecting an expression but encountered the end of the command. >Check the expression for omitted or extra operands, operators, and >parentheses. >This command not executed. Any suggestions? -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marks, Jim Sent: Friday, July 21, 2006 3:03 PM To: [hidden email] Subject: Re: Identify Users Syntax IF ( code ) and IF (code) is not legal. Try IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. This will evaluate both brackets and set BakerUser to "0" when both are true. You can use IF ANY(0, q4a1 TO q4a18) AcmeUser = 0. To evaluate a set of contiguous variables. Remember that you could have both 0 and 1 in your set of variables-- SPSS will evaluate the IF statements in order. Marke sure the last statement is one you want to "dominate" the code. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Friday, July 21, 2006 2:37 PM To: [hidden email] Subject: Identify Users Syntax I need some syntax to create a numeric variable named BakerUser based on 3 non-contiguous variables. All 3 variables contain either a system missing code or a 1 or a zero. If all 3 non-contiguous variables are system missing then BakerUser should be given a value of system missing. If none of the 3 non-contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then BakerUser should be given a value of 0. If any of the 3 non-contiguous variables contain a value of 1 then BakerUser should be given a value of 1. I tried writing this syntax: COMPUTE BakerUser=$sysmis. EXECUTE. IF(q4a23=1 or q4a29=1 or q4a32=1) BakerUser=1. EXECUTE. FORMAT BakerUser (f1.0). IF(q4a23~=1 and q4a29~=1 and q4a32~=1) AND IF (q4a23=0 or q4a29=0 or q4a32=0) BakerUser=0. EXECUTE. It crashes on the IF command with the following error message: Error#4023 in column 44. Text: IF An expression contains a string of characters followed by a left parenthesis, indicating that the string of characters is a function or vector name, but the characters do not match any existing function or vector. Check the spelling. This command not executed. Any suggestions? I also need some syntax to create a numeric variable named AcmeUser based on the values of 18 contiguous variables named q4a1 to q4a18. All 18 variables are either system missing or they contain either a 1 or a zero. If all 18 contiguous variables are system missing then AcmeUser should be given a value of system missing. If none of the 18 contiguous variables contain a 1 and one or more of the 18 contiguous variables contain a 0 then AcmeUser should be given a value of 0. If any of 18 contiguous variables contain a value of 1 then AcmeUser should be given a value of 1. How would I write syntax similar to that noted above where the original variables are contiguous without having to list all eighteen variables. Thanks for your help. |
Free forum by Nabble | Edit this page |