Quartz | Level 8

## Calculating a field

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
2 REPLIES 2
Garnet | Level 18

## Re: Calculating a field

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; ``````

Quartz | Level 8

## Re: Calculating a field

Thank you! It worked!

Discussion stats
• 2 replies
• 355 views
• 0 likes
• 2 in conversation