BookmarkSubscribeRSS Feed
ssitharath0420
Quartz | Level 8

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
Shmuel
Garnet | Level 18

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; 

 

ssitharath0420
Quartz | Level 8

Thank you! It worked!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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