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 (November 2000, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 13 Nov 2000 14:22:34 -0600
Reply-To:   Jonathan_Goldberg@MASTERCARD.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jonathan Goldberg <Jonathan_Goldberg@MASTERCARD.COM>
Subject:   Re: Explode Data Set
Comments:   To: dousk8@HOTMAIL.COM
Content-type:   text/plain; charset=us-ascii

> From: Nigel Tufnel [mailto:dousk8@HOTMAIL.COM] > I need to explode a sas data set a bit. > I have a data set something like the following: > > ProdCode population owner list > 101 c 1 a > 102 c 1,2 b > 103 c 1,2 c,d > 104 c,h 2,3,4 d,e > I need to explode and repeat records (by prodcode) where > there is more than > 1 element in the field (seperated by commas)

This can be done with nested loops and scan in one pass over the data. Assuming that the lists of population, owner and list are read as gr_pop, gr_owner, and gr_list, the following should do it:

data whatever(keep = ProdCode population owner list); /*input here*/ i = 1; population = scan(gr_pop, i, ','); do while (population ^= ' '); j = 1; owner = scan(gr_owner, j, ','); do while (owner ^= ' '); k = 1; list = scan(gr_list, k, ','); do while (list ^= ' '); output; k + 1; list = scan(gr_list, k, ','); end; /*over list*/ j + 1; owner = scan(gr_owner, j, ','); end; /*over owner*/ i + 1; population = scan(gr_pop, i, ','); end; /*over pop*/

Jonathan


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