```Date: Wed, 6 Aug 2008 16:05:50 -0400 Reply-To: Gene Maguin Sender: "SPSSX(r) Discussion" From: Gene Maguin Subject: Re: Searching string-variables for numbers separated by comma and recoding into new variables In-Reply-To: <000001c8f66c\$e3c357b0\$ab4a0710\$@dk> Content-Type: text/plain; charset="us-ascii" Claus, >>I have 6 string variables which all contain up to 13 numbers between 1 and 21. Each number is separated by a comma. >>What I would like to do is to make a syntax that instead of 6 variables containing these numbers have a variable for each of the numbers between 1 and 21 coded dichotomously so that if the number is present in any of the 6 variables the variable for each value is coded 1 and if not it is coded as 0. >>So I need a syntax able to searches through each of the 6 variables and recode each of the value into the new variables. First, combine your six string vars into one much longer one using Concat. Suppose the six vars are s1 to s6(a40). AND, there are no embedded blanks or blank vars! Every var must have a number in it! Then, * combine vars into one long var. String sall(a250). Compute sall=concat(rtrim(s1),',',rtrim(s2),',',rtrim(s3),',',rtrim(s4),',', rtrim(s5),',',rtrim(s6)). Compute len=index(sall,' ')-1. /* sall has to be long enough to have two blanks at end. Vector numbers(21). * locate commas, extract numbers. Compute #last=1. Loop #i=1 to len. Do if (substr(sall,#i,1) eq ','). + compute value=number(substr(sall,#last,(#i-#last)),f2.0). + compute numbers(value)=1. + compute #last=#i+1. End if. End loop. * extract last number. compute value=number(substr(sall,#last,(len-#last+1)),f2.0). compute numbers(value)=1. Execute. * if you have troubles let me know. Gene Maguin ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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 ```

Back to: Top of message | Previous page | Main SPSSX-L page