I hope someone can help my old eyes out. I have written some code that basically takes multiple values in a cell (e.g., 1,2,3) and creates new variables for each individual value. The problem that I am encountering is that the code that I have written adds a comma at the end of the original value (e.g., 1,2,3,). Below is the code, any help would be greatly appreciated. * Encoding: UTF-8. DEFINE !parse (var=!TOKENS(1) /nbval=!TOKENS(1)) COMPUTE !var=CONCAT(RTRIM(!var),','). STRING #str(A8). VECTOR !var (!nbval F8.0). COMPUTE #beg=1. LOOP #cnt=1 TO !nbval. +COMPUTE #str=CHAR.SUBSTR(!var,#beg). +COMPUTE #end=CHAR.INDEX(#str,',')-1. +DO IF #end=-1. + BREAK. +END IF. +COMPUTE !var(#cnt)=NUMBER(CHAR.SUBSTR(#str,1,#end),F8.0). +COMPUTE #beg=#beg+#end. END LOOP IF #end=-1. EXECUTE. !ENDDEFINE. * Call the macro. !parse var=var1 nbval=7. !parse var=var2 nbval=9. J
|
Administrator
|
See the RTRIM function!
--
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?" |
In reply to this post by Scott Roesch
Isn't there an extension command to exactly this?
Art Kendall
Social Research Consultants |
See SPSSINC CREATE DUMMIES (Transform > Create Dummy Variables). It has a number of related features for dummy variable creation. On Thu, Apr 6, 2017 at 5:43 AM, Art Kendall <[hidden email]> wrote: Isn't there an extension command to exactly this? -- |
In reply to this post by Scott Roesch
Visit my page http://www.spsstools.net/en/KO-spssmacros/
In collection Categorical-Binary Recodings there are macros !catbin - recode nominal variable(s) to binary, dummy ones !mrcmrd - recode MR set of categorical variables into MR dichotomous set etc In collection Multiple-Response Tools !strmrc or !strmrd - create categorical MR set or dichotomous MR set from a string variable containing codes (there several modes codes packing are considered) ===================== 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 |