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 10:13:52 -0500
Reply-To:     "Johnson, Wendy SBCCOM(N)" <>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Johnson, Wendy SBCCOM(N)" <>
Subject:      Re: String variables:  breaking a list into it's parts
Content-Type: text/plain; charset="iso-8859-1"

Thanks to everyone who responded to my question. As a result, I've come up with syntax which will count the commas, then run a loop based on the number of commas. Because SPSS won't let me use a variable to define a vector, and because the length of the string is known, I've made a ridiculous number of vector variables based on string length.

Thanks again, Wendy.


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. exe.

*COMPUTE THE NUMBER OF COMMAS . compute n_commas = 0. loop #next = 1 to 80. if substr(list, (#next),1) eq "," n_commas = n_commas + 1. end loop. *THE NUMBER OF ITEMS WILL BE ONE MORE THAN THE NUMBER OF COMMAS. compute n_items = n_commas + 1 . exe.

*BREAK THE LIST INTO INDIVIDUAL ITEMS. vector list(80,a80) . loop #next = 1 to n_items 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 . end if. end loop . exe.

*MAKE A WIDE FILE LONG. VARSTOCASES /MAKE items FROM list1 to list80 /INDEX = order (80) /KEEP = id /NULL = KEEP.

*REMOVE EXTRA LINES. select if (items ne ""). compute items = lower(items). freq /var items.


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