Date: Tue, 3 Dec 2002 09:26:14 +1100
Reply-To: Simon Freidin <email@example.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Simon Freidin <firstname.lastname@example.org>
Subject: Re: String variables: breaking a list into it's parts
Content-type: text/plain; charset="us-ascii"; format=flowed
At 01:06 PM 12/2/2002 -0500, Johnson, Wendy SBCCOM(N) wrote:
>I often have open-ended responses in my data sets, including lists of
>items separated by commas, like so:
>What I want is to find out how many times each item was mentioned. To do
>this, I've come up with some syntax which will take a list and break it
>down into individual items (see below). Basically it works, but I have to
>know (or guess) the greatest
>number of items in any given list. This will never be the case. Any
>suggestions (or general comments) would be greatly appreciated.
set printback=listing mxwarns=0.
data list list (tab)/id (f4) list (a80).
3333 cheese, peanut butter
4213 beef curry, green eggs and ham, skittles
1125 cigarettes, beverage base, m&ms, gatorade, twix
1238 gum, peanuts, grape juice, coffee, potato chips
/* write data out so can read back comma delimited (up to 1000 30-char
items per case) */
write outfile='c:\temp\list.txt'/id ',' list.
data list file='c:\temp\list.txt' list (",")/id (f4) item1 to item1000
/* write out individual items (if they exist) comma delimited */
do repeat x=item1 to item1000.
do if x ne ''.
write outfile='c:\temp\list2.txt'/id ',' x.
/* read individual items */
data list file='c:\temp\list2.txt' list (",")/id (f4) item (a30).
/* strip space prefixes and set to lower case (or use upcase if you prefer) */
if substr(item,1,1)=' ' item=substr(item,2).
Research Database Manager and Analyst
Melbourne Institute of Applied Economic and Social Research
The University of Melbourne
MELBOURNE VIC 3010
Tel: (03) 8344 3601 Fax: (03) 8344 5630