LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2002)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 3 Dec 2002 09:26:14 +1100
Reply-To:     Simon Freidin <s.freidin@iaesr.unimelb.edu.au>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Simon Freidin <s.freidin@iaesr.unimelb.edu.au>
Subject:      Re: String variables:  breaking a list into it's parts
Comments: To: "Johnson, Wendy SBCCOM(N)" <Wendy.Johnson@natick.army.mil>
In-Reply-To:  <8AE0F8238A85D94A97151B5462C8BA7F4061C9@natickexch02.natick.army.mil>
Content-type: text/plain; charset="us-ascii"; format=flowed

At 01:06 PM 12/2/2002 -0500, Johnson, Wendy SBCCOM(N) wrote: >Hello, > >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). begin data 2341 skittles 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 end data. execute.

/* 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. execute. data list file='c:\temp\list.txt' list (",")/id (f4) item1 to item1000 (1000a30). execute.

/* 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. end if. end repeat. execute.

/* read individual items */ data list file='c:\temp\list2.txt' list (",")/id (f4) item (a30). execute. /* strip space prefixes and set to lower case (or use upcase if you prefer) */ if substr(item,1,1)=' ' item=substr(item,2). compute item=lower(item).

freq vars=item.

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


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