Hello,
Please help! I am trying to calculate a field where one total sum is in another table and the other field is in another table.
The field in locate in one table that sum the total number of members utilizing a product.
data Tbl_1_row15;
set Tbl_1_row15;
Status='Members on Product A';
run;
Then I have another table that generate the total member by pharmacy. I am trying to generate the field % of Total Product A Members. Taking the total in the field 7/1/20 - 12/31/2020 divided by the total member on product A and so forth.
n of pharmacies | 7/1/20 - 12/31/2020 | % of Total Product A Members |
n ≥ 1 | - | 0.00% |
n ≥ 4 | - | 0.00% |
n = 3 | - | 0.00% |
n < 3 | 1 | 0.20% |
n ≥ 3 | 3 | 0.59% |
n < 3 | 7 | 1.38% |
n ≥ 3 | 1 | 0.20% |
n < 3 | 495 | 97.63% |
7/1/20 - 12/31/2020 | |
Members on Product A | 507 |
So your input is two tables, let's create them:
data tabl_1;
total = 507;
run;
data tabl_2;
input freq;
datalines;
.
.
1
3
7
1
495
;run;
next step will be to merge those two tables and calculate the percentage:
data want;
retain total;
set tabl_2;
if _N_ = 1 then set tabl_1;
if missing(freq) then percent=.;
else percent = freq/total*100;
format percent 6.2;
run;
Thank you! It worked!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for 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.