|
Hi all,
I've searched at the files a clue that break a string variable at others but I didn't find. I have a variable as X 1,2 1 2,3 1,3 And I want to split in 3 variables in order to calcule the multiple response. As I have a string variable I tried the INDEX command, but it didn't come with the right results. compute X_1 = index(X,'1'). compute X_2 = index(X,'2'). compute X_3 = index(X,'3'). exe. I really don't know what I am doing wrong. Any help. Thanks, Ribeiro ===================== 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 Ribiero,
You're almost there. Your current code evaluates for the position of the test value (either 1, 2 or 3) within the string, when you want to test for the *presence* of the value. Try the code below: compute X_1 = index(X,'1') <> 0. compute X_2 = index(X,'2') <> 0. compute X_3 = index(X,'3') <> 0. exe. HTH, John Norton SPSS Inc. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ribeiro Sent: Thursday, January 17, 2008 3:47 PM To: [hidden email] Subject: Break String Variable Hi all, I've searched at the files a clue that break a string variable at others but I didn't find. I have a variable as X 1,2 1 2,3 1,3 And I want to split in 3 variables in order to calcule the multiple response. As I have a string variable I tried the INDEX command, but it didn't come with the right results. compute X_1 = index(X,'1'). compute X_2 = index(X,'2'). compute X_3 = index(X,'3'). exe. I really don't know what I am doing wrong. Any help. Thanks, Ribeiro ===================== 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 Marcioestat
Hi Melissa,
Well, technically, you are correct; the index function would not result a negative number. But given that Ribiero is after a logical evaluation for whether a character exists in a string or not, I use the "<>" characters to mean "not equal to." So, if a character does not exist in a string, then the index function returns a 0. The code I suggested would determine whether a character existed, and if it did, then the location of that character would be not equal to 0, rendering the logical evaluation as true and assigning a value of 1 to the target variable. HTH, John Norton SPSS Inc. -----Original Message----- From: Melissa Ives [mailto:[hidden email]] Sent: Thursday, January 17, 2008 4:35 PM To: Norton, John Subject: RE: Re: [SPSSX-L] Break String Variable When would an index result a negative number? Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Norton, John Sent: Thursday, January 17, 2008 4:22 PM To: [hidden email] Subject: Re: [SPSSX-L] Break String Variable Hi Ribiero, You're almost there. Your current code evaluates for the position of the test value (either 1, 2 or 3) within the string, when you want to test for the *presence* of the value. Try the code below: compute X_1 = index(X,'1') <> 0. compute X_2 = index(X,'2') <> 0. compute X_3 = index(X,'3') <> 0. exe. HTH, John Norton SPSS Inc. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ribeiro Sent: Thursday, January 17, 2008 3:47 PM To: [hidden email] Subject: Break String Variable Hi all, I've searched at the files a clue that break a string variable at others but I didn't find. I have a variable as X 1,2 1 2,3 1,3 And I want to split in 3 variables in order to calcule the multiple response. As I have a string variable I tried the INDEX command, but it didn't come with the right results. compute X_1 = index(X,'1'). compute X_2 = index(X,'2'). compute X_3 = index(X,'3'). exe. I really don't know what I am doing wrong. Any help. Thanks, Ribeiro ===================== 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 ===================== 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 |
