Re: SPSS

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

Re: SPSS

muthu kkumaran
Hi,

I am a new member in the list of SPSS. Need help on the below.
Have one string variable of 6 length. On which the data is like
010204

I need to convert this like the below format.

v1  v2  v3  v4
01  02  00  04

Here v3 is 00 because you dont have data for "03" .

Request your help on this.

Rgds.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: SPSS

David Marso
Administrator
Look at the COMPUTE command CHAR.SUBSTR string function, NUMBER function and N format!
eg COMPUTE x1=NUMBER(CHAR.SUBSTR(your_var,1,2),N2).
etc for X2 and X3 .
muthu kkumaran wrote
Hi,

I am a new member in the list of SPSS. Need help on the below.
Have one string variable of 6 length. On which the data is like
010204

I need to convert this like the below format.

v1  v2  v3  v4
01  02  00  04

Here v3 is 00 because you dont have data for "03" .

Request your help on this.

Rgds.

=====================
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
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: SPSS

Bruce Weaver
Administrator
In reply to this post by muthu kkumaran
From the original post:  "Here v3 is 00 because you dont have data for "03" ."

I'm still trying to work out exactly what you're asking.  Is the string variable equal to '010204' on every row in the file, or only some of the rows?  E.g., might you have '010203', '010304', '020304', and so on on other rows in the file?  

If you have 010204 on every row and just want variables v1-v4 equal to 01, 02, 00 and 04, then just compute them in a DO-REPEAT and give them an N-format.

DO REPEAT v = v1 to v4 / # = 1 2 0 4 .
- COMPUTE v = #.
END REPEAT.
formats v1 to v4 (n2.0).

If the string value can have different values on different rows, then maybe something like this will give what you want.

DATA LIST LIST / stringvar (a6).
BEGIN DATA
010203
010204
010304
020304
END DATA.

NUMERIC v1 to v4 (n2.0).
RECODE v1 to v4 (else=0).
DO REPEAT v = v1 to v4 / # = 1 to 4 .
- IF INDEX(stringvar,string(#,f1)) GT 0 v = #.
END REPEAT.
FORMATS v1 to v4 (n2.0).
LIST.

OUTPUT:

stringvar v1 v2 v3 v4
 
010203    01 02 03 00
010204    01 02 00 04
010304    01 00 03 04
020304    00 02 03 04
 
Number of cases read:  4    Number of cases listed:  4

HTH.


muthu kkumaran wrote
Hi,

I am a new member in the list of SPSS. Need help on the below.
Have one string variable of 6 length. On which the data is like
010204

I need to convert this like the below format.

v1  v2  v3  v4
01  02  00  04

Here v3 is 00 because you dont have data for "03" .

Request your help on this.

Rgds.

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).