Date: Mon, 2 Dec 2002 15:07:31 -0600
Reply-To: "Wall, Deborah A." <walld@umkc.edu>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Wall, Deborah A." <walld@umkc.edu>
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.
Deborah Wall
Business Technology Analyst
WallD@umkc.edu -- 816.235.1184
UMKC Information Services
5115 Oak - Room 216
Kansas City, MO 64110-2499
-----Original Message-----
From: Johnson, Wendy SBCCOM(N) [mailto:Wendy.Johnson@natick.army.mil]
Sent: Monday, December 02, 2002 12:06 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: String variables: breaking a list into it's parts
Hello,
I often have open-ended responses in my data sets, including lists of
items separated by commas, like so:
ID LIST
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
3124
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,
Wendy.
**BEGIN SYNTAX** .
string oldlist (a75).
compute oldlist = list.
*ASSUME that there are no more than 5 items in any list.
vector list(5,a75).
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).
else .
compute list(#next) = list.
compute list = "end".
end if.
end loop.
exe.
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
Research Psychologist
Supporting Science and Technology Directorate
U.S. Army Natick Soldier Center, SBCCom
Natick, MA 01760-5020
|