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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.