|Date: ||Wed, 6 Aug 2008 16:05:50 -0400|
|Reply-To: ||Gene Maguin <email@example.com>|
|Sender: ||"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>|
|From: ||Gene Maguin <firstname.lastname@example.org>|
|Subject: ||Re: Searching string-variables for numbers separated by comma and
recoding into new variables|
|Content-Type: ||text/plain; charset="us-ascii"|
>>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
>>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.
Compute len=index(sall,' ')-1. /* sall has to be long enough to have two
blanks at end.
* locate commas, extract numbers.
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.
* extract last number.
* if you have troubles let me know.
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
For a list of commands to manage subscriptions, send the command