SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Agent1592
Pyrite | Level 9

Dear Sas Community:

I am trying to calculate a a weighted Average Interest Rate for a company that may have several subsidiaries that borrow at different interest rates.

I have the following table:

CompanyNumSubsidiaryNumAmountRate
12345000000355
12435000000405

 

I want the following table:

CompanyNumTotal AmountWeighted Average Rate
180000000376.875

 

How can I do that using SAS Proc SQL. Any suggestions. Basically I would like to have my analysis at the company level.

2 REPLIES 2
chrej5am
Quartz | Level 8

data watch;
input CompanyNum SubsidiaryNum Amount Rate;
datalines;
1 23 45000000 355
1 24 35000000 405
;

run;

 

 

proc sql;
select
CompanyNum,
sum(Amount) as Total_Amount,
sum(Amount*Rate)/sum(Amount) as wRate
from watch
group by CompanyNum;
quit;

mkeintz
PROC Star

Why not use the procedure that SAS intended for this purpose?  It would be easy to expand the number of vars, or request other statistics (std, var, min, max, median, various percentiles etc.)

 

proc summary data=have noprint nway ;

  class companynum;

  var rate;

  weight amount;

  output out=want (drop=_type_ _freq_) sumwgt(rate)=total_amount mean(rate)=wrate ;

run;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2116 views
  • 9 likes
  • 3 in conversation