Solved
Contributor
Posts: 65

# 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;
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;
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.

Accepted Solutions
Solution
‎03-29-2018 08:58 AM
Super User
Posts: 10,530

## 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;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Solution
‎03-29-2018 08:58 AM
Super User
Posts: 10,530

## 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;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 65