I am trying to merge two SAS tables based on a third “bridge table” and perform some calculations during the process. The code should be like “For each good lookup the price and calculate the annual revenue.”
My raw data: one table with annual quantity of goods, one table with prices and one bridge table with the information which price is used for which good.
data work.goods;
input date date. GoodA GoodB GoodC;
format date year. ;
datalines;
01Jan20 10 12 2
01Jan21 12 11 5
run;`
data work.price;
input date date. PriceA PriceB;
format date year.;
datalines;
01Jan20 220 110
01Jan21 250 120
run;
data work.bridgetable;
input goods $5. price $7.;
datalines;
GoodA PriceA
GoodB PriceB
GoodC PriceB
run;
So far, I used a proc sql statement without the information in the bridge table.
proc sql;
create table work.result as
select goods.date,
goods.GoodA * price.PriceA as RevenueA,
goods.GoodB * price.PriceB as RevenueB,
goods.GoodC * price.PriceB as RevenueC
from work.goods as goods, work.price as price
where goods.date = price.date;
quit;
Now, I would like to use the information from the bridge table, so that I can change the assignment of a price to a good (e.g. instead of PriceB PriceA is used for GoodC). In addition, I’d like to have the code more dynamic without the hardcoding so that I can add new goods and prices in my tables without re-coding the ‘select’ part of my sql statement.
How do I implement the bridge table in proc sql?
Thanks a lot for your help!