Date: Fri, 2 Nov 2001 09:00:45 -0800
Reply-To: John <jdvona@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John <jdvona@YAHOO.COM>
Organization: http://groups.google.com/
Subject: how-to square up a dataset
Content-Type: text/plain; charset=ISO-8859-1
Thanks to all who have helped me progress up the learning curve
through your helpful code snippets, which I am now using for other
applications. I have yet another conundrum that I cannot get my arms
around. I have to "Square" up a dataset to include zeros for missing
products. In other words, for each key-regime-period combination, see
below, there should be 5 products, 1 through 5.
If there is not a product for a given combination, then add the
product and give it a zero volume. For instance, below the first
key-regime-period combination has a full set, 1 thru 5 products. But
the second set (3-92-5), is missing product 2. So, I'd like to
insert one record 3 92 5 2 0.0.
Not understanding how SAS reads thru a dataset makes it difficult to
grasp the logic for designing a solution. Perhaps you can advise me.
Thank you in advance.
Data product;
Key Regime Period ProdID ProdVolume
1 91 2 1 2.4
1 91 2 2 3.1
1 91 2 3 2.2
1 91 2 4 3.4
1 91 2 5 1.1
3 92 5 1 1.8
3 92 5 3 4.2
3 92 5 4 6.4
3 92 5 5 8.1
I started with a simple idea and am stumped:
data newproduct; set product;
by key regime period;
If (first.key or first.regime or first.period) then do;
<<<do something here to cycle thru the 5 products and add
the missing product, plus a 0 prodvolume.>>
John