08-11-2016 09:15 AM
I am reading monthly sales data from a SAS dataset called RAW but I need to break it out into its 7 components for that given month. How would I modify my PROC SQL code to allow me to break this out so I can generate the the monthly sales revenue for products 'a' thru 'g' in a given month? For simplicity assume the shares are equal at 14.3% and I want to hard code the revenue shares into the coding. How would I modify the SQL language below to accomplish this?
proc sql; create table other_revenue as select Date as yyyymm, OtherRevenue as revenue format comma9. from raw; alter table other_revenue add product char (2) ; insert into other_revenue set product='a'; * there are 6 more products (b,c,d,e,f,g); quit;
08-11-2016 09:22 AM
could you please supply some example data against which we can run your SQL step to see what is intended?
And some example how the data should look like after the transformation?
The way I see it, you add 7 additional observations where "product" contains the letters "a" through "g", while in all existing observations coming from raw "product" remains missing.
08-11-2016 09:51 AM
Sure...here is what I am trying to do.
Go from something like this:
Alternatively would it be easier to do this as a SAS data step?
08-11-2016 11:55 AM
I guess the share values can be calculated at the start or for each month?
I'd recommend creating a table holding the product names and share quotes, and then do a cartesian join with SQL.
08-12-2016 02:38 AM
Example code for my previous suggestion:
data shares; input yyyymm $ product $ shr; cards; 201606 a 0.05 201606 b 0.07 201606 c 0.25 201606 d 0.07 201606 e 0.3 201606 f 0.07 201606 g 0.19 ; run; data revenue; input yyyymm $ revenue; cards; 201606 1500 ; run; proc sql; create table want as select a.yyyymm, (a.revenue * b.shr) as revenue, b.product from revenue as a, shares as b where a.yyyymm = b.yyyymm ; quit;
If you get your shares in wide rather than long format, a proc transpose will be needed.