I have this table that have the volume for each product:
PRODUCT | VOLUME |
NK | 200 |
CN | 180 |
CY | 220 |
And another table the have the percentage share for each country:
REGION | SHARE |
AUSTRALIA | 0.45 |
CHINA | 0.55 |
I want this output, the propotion the volume of each product by each country
PRODUCT | REGION | VOLUME |
NK | AUSTRALIA | 90 |
NK | CHINA | 110 |
CN | AUSTRALIA | 81 |
CN | CHINA | 99 |
CY | AUSTRALIA | 99 |
CY | CHINA | 121 |
How do I achieve this in PROC SQL? I have simplified the table, in real there are more columns.
You're looking for a cross join or natural join.
You can use a.*, b.* to specify keeping all columns in each table.
proc sql;
create table want as
select a.*, b.*, a.volume*b.share as volume_proportion
from table1 as a
CROSS JOIN table2 as b
order by a.product, b.region;
quit;
You're looking for a cross join or natural join.
You can use a.*, b.* to specify keeping all columns in each table.
proc sql;
create table want as
select a.*, b.*, a.volume*b.share as volume_proportion
from table1 as a
CROSS JOIN table2 as b
order by a.product, b.region;
quit;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.