Morning Lads,
I wanted to ask an urgent question about calculating percentages from 2 different tables. In the first picture you see the total measurements per month/section.
In the second picture you see a the total measurements per MatType per month per section.
Now I want to calculate the percentages of subtotal/total in a new table but if I join the tables i get the wrong totals. So I actually want 21 (from second table) / 112 (from first table) and 6 (from second table) / 52 (from first table).
Please note that I use the query builders most of the time instead of coding (also note that these are just screenshots, the tables are much much bigger.
Now I want to calculate the percentages of subtotal/total in a new table but if I join the tables i get the wrong totals.
What is wrong when you do this? How are you doing it?
So I actually want 21 (from second table) / 112 (from first table) and 6 (from second table) / 52 (from first table).
I don't understand the part in red.
As I told you in our private conversation, you need to deliver usable example data. And what you expect to get out of it.
Expand this for table 1:
data table1;
input sectie $ maand2 :date9. totaal;
format maand2 yymon7.;
datalines;
2632CT 01jul2019 112
;
and provide a similar step for table 2. It is not rocket science, and it helps you learn basic data step technique, which is essential for further progress in using SAS to its fullest.
See this example:
data table1;
input sectie $ maand :date9. totaal;
format maand yymon7.;
datalines;
2632CT 01jul2019 112
;
data table2;
input sectie $ maand2 :date9. subtotaal mattype $;
format maand2 yymon7.;
datalines;
2632CT 01jul2019 22 DDM
;
proc sql;
create table want as
select
t1.sectie,
t1.maand,
t2.subtotaal,
t2.subtotaal / t1.totaal as percentage format=percent7.2
from table1 t1, table2 t2
where t1.sectie = t2.sectie and t1.maand = t2.maand2;
quit;
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.