🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quartz | Level 8

## Proc means - Calculating the share / weight

I am using a proc means to calculate the share of the payments made by business line, the data looks like this:

``````data Test;
input ID Business_Line Payment2017;
Datalines;
1 1 1000
2 1 2000
3 1 3000
4 1 4000
5 2 500
6 2 1500
7 2 3000
;
run;``````

i'm looking to calculate an additional column which, by group (business_line) calculates the percentage share (weight) of the payment as such:

``````   data Test;
input ID Business_Line Payment2017 share;
Datalines;
1 1 1000 0.1
2 1 2000 0.2
3 1 3000 0.3
4 1 4000 0.4
5 2 500 0.1
6 2 1500 0.3
7 2 3000 0.6
;
run;``````

the code I have used so far:

``````proc means data = test noprint;
class ID;
var Payment2017;
output out=test2
sum = share;
weight = payment2017/share;
run;``````

I have also tried

``````proc means data = test noprint;
class ID;
var Payment2017 /weight = payment2017;
output out=test3 ;
run;``````

appreciate the help.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Proc means - Calculating the share / weight

Do it in SQL:

``````proc sql;
create table want as
select a.*, payment2017 / sum(payment2017) as share
from test a
order by id
;
quit;``````
2 REPLIES 2
Super User

## Re: Proc means - Calculating the share / weight

Do it in SQL:

``````proc sql;
create table want as
select a.*, payment2017 / sum(payment2017) as share
from test a
order by id
;
quit;``````
Quartz | Level 8

## Re: Proc means - Calculating the share / weight

I always forget about SQL

Discussion stats
• 2 replies
• 962 views
• 1 like
• 2 in conversation