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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.