Date: Mon, 2 Dec 2002 15:07:31 -0600
Reply-To: "Wall, Deborah A." <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Wall, Deborah A." <email@example.com>
Subject: Re: String variables: breaking a list into it's parts
Content-Type: text/plain; charset="us-ascii"
Have you just tried using a longer number? So, if the list is no more
than 75 character, use 75 instead of 5. This will give you a lot of
empty cases, but it should also give you a full count of your values.
Business Technology Analyst
WallD@umkc.edu -- 816.235.1184
UMKC Information Services
5115 Oak - Room 216
Kansas City, MO 64110-2499
From: Johnson, Wendy SBCCOM(N) [mailto:Wendy.Johnson@natick.army.mil]
Sent: Monday, December 02, 2002 12:06 PM
Subject: String variables: breaking a list into it's parts
I often have open-ended responses in my data sets, including lists of
items separated by commas, like so:
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
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.
Thanks for your help,
**BEGIN SYNTAX** .
string oldlist (a75).
compute oldlist = list.
*ASSUME that there are no more than 5 items in any list.
loop #next = 1 to 5 by 1.
COMPUTE comma = INDEX(list,',') .
do if (comma ne 0).
compute list(#next) = substr(list,1,comma-1).
compute list = substr(list,comma+2).
compute list(#next) = list.
compute list = "end".
VARSTOCASES /MAKE items FROM list1 list2 list3 list4 list5
/INDEX = order (5)
/KEEP = id
/NULL = KEEP.
compute items = lower(items).
freq /var items.
**END SYNTAX** .
Wendy K. Johnson
Supporting Science and Technology Directorate
U.S. Army Natick Soldier Center, SBCCom
Natick, MA 01760-5020