I would like to obtain the commission for all sales achieved. Anyone can help? Thanks.
The desired would be:
ID Sales Commission
111 400 400
111 200 200
111 200 200
112 600 600
112 250 250
112 100 100
112 50 50
113 120 280
113 180 420
114 200 400
114 300 600
114 100 200
data Comm;
input ID Commission;
datalines;
111 800
112 1000
113 700
114 1200
;
run;
data sales;
input ID Sales;
datalines;
111 400
111 200
111 200
112 600
112 250
112 100
112 50
113 120
113 180
114 200
114 300
114 100
;
run;
I think the following will do what you want:
data salesplus; do until (last.id); set Sales; by id; if first.id then total=sales; else total+sales; end; do until (last.id); set Sales; by id; cpart=sales/total; output; end; run; data want (drop=total cpart _:); merge comm (rename=(commission=_commission)) salesplus; by id; commission=_commission*cpart; run;
Art, CEO, AnalystFinder.com
proc sql;
create table new as select id, sum(sales) as tot_sales from sales group by id;
select sales.id,sales,(commission/tot_sales)*sales as final_commission
from sales left join new on sales.id=new.id
left join comm on sales.id=comm.id;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.