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. ===================== 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 |
There must be a more efficient way to do this, but here's a solution.
*create the variables -- change the 4 in the loop command to whatever the maximum value is. VECTOR V=C1 TO C4. LOOP #I=1 TO 4. COMPUTE V(#I)=0. END LOOP. EXECUTE. *assuming your 6-character string variable is called v1. VECTOR V=C1 TO C4. LOOP #I = 1 TO 6 BY 2. COMPUTE #D = NUMBER((SUBSTR(v1,#I,2)),F2). IF #D NE 0 V(#D)=#D. END LOOP. EXECUTE. -- Florio -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of muthu kkumaran Sent: Thursday, March 29, 2012 6:41 AM To: [hidden email] Subject: Fw: Re: SPSS 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. ===================== 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 |
Administrator
|
Hi Florio. Your response ended up in a different thread in the Nabble archive, so I didn't see it right away. I like your VECTOR & LOOP approach for assigning values to the variables. For creating the variables in the first place, you could do this rather than looping:
*create the variables. NUMERIC C1 to C4 (n2.0). RECODE C1 to C4 (else=0).
--
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/). |
Free forum by Nabble | Edit this page |