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