extract a string into separate cells

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

extract a string into separate cells

huang jialin
Hello,

I have a cell containing with a single string, like #AABCAAABC BCABCBCABCABADABCABAABACABABCDACAAACBAAA.

I am trying to separate them into different cells, and give each cell a name. The syntax as following does not work, SPSS gave an error about "invalid variable name". How can I solve the problem?

Loop #i=1 to 50.
      compute @i=substr(ResponseString,i,1).
end loop.

I would appreciate your inputs on it. Thank you very much.

Sincerely,
Jialin Huang

Reply | Threaded
Open this post in threaded view
|

Re: extract a string into separate cells

Maguin, Eugene

Vector cell(50,a1).

Loop #i=1 to 50.
      compute cell(#i) = substr(ResponseString,i,1).
end loop.

Gene Maguin

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of huang jialin
Sent: Monday, October 01, 2012 11:41 AM
To: [hidden email]
Subject: extract a string into separate cells

 

Hello,

I have a cell containing with a single string, like #AABCAAABC BCABCBCABCABADABCABAABACABABCDACAAACBAAA.

I am trying to separate them into different cells, and give each cell a name. The syntax as following does not work, SPSS gave an error about "invalid variable name". How can I solve the problem?

Loop #i=1 to 50.
      compute @i=substr(ResponseString,i,1).
end loop.

I would appreciate your inputs on it. Thank you very much.

Sincerely,
Jialin Huang

Reply | Threaded
Open this post in threaded view
|

Re: extract a string into separate cells

David Marso
Administrator
In reply to this post by huang jialin
Look up VECTOR in the FM or search the archives of this group.
Note also that #i is not the same thing as i .
You also need to declare/preallocate string variables with STRING declarative .
Your code is simply going to create a single variable @i corresponding to the 50th character of ResponseString.
--
huang jialin wrote
Hello,

I have a cell containing with a single string, like #AABCAAABC
BCABCBCABCABADABCABAABACABABCDACAAACBAAA.

I am trying to separate them into different cells, and give each cell a
name. The syntax as following does not work, SPSS gave an error about
"invalid variable name". How can I solve the problem?

Loop #i=1 to 50.
      compute @i=substr(ResponseString,i,1).
end loop.

I would appreciate your inputs on it. Thank you very much.

Sincerely,
Jialin Huang
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: extract a string into separate cells

David Marso
Administrator
In reply to this post by Maguin, Eugene
The devil is in the details ;-)
--
Maguin, Eugene wrote
Vector cell(50,a1).
Loop #i=1 to 50.
      compute cell(#i) = substr(ResponseString,i,1).
end loop.

Gene Maguin

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of huang jialin
Sent: Monday, October 01, 2012 11:41 AM
To: [hidden email]
Subject: extract a string into separate cells

Hello,

I have a cell containing with a single string, like #AABCAAABC BCABCBCABCABADABCABAABACABABCDACAAACBAAA.

I am trying to separate them into different cells, and give each cell a name. The syntax as following does not work, SPSS gave an error about "invalid variable name". How can I solve the problem?

Loop #i=1 to 50.
      compute @i=substr(ResponseString,i,1).
end loop.

I would appreciate your inputs on it. Thank you very much.

Sincerely,
Jialin Huang
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"