BookmarkSubscribeRSS Feed
tim-hahn
Fluorite | Level 6

Thank you very much for taking time to read this post.

 

I have a column "ICBSUN" with industry classification codes and a separate column "EV/EBITDA" with an EBITDA multiple.

Now I would like to create a new column "Peer Multiple" that takes the Harmonic mean of the "EV/EBITDA" Coulomn of all Companies with the ICBSUC Code 452010 except the one company of the row itself.

 

So for example to get the first Value in the "Peer Multiple" Column for the table below it should take the Harmonic mean of the rows 2-12 from column "EV/EBITDA". 

 

However the amount of companies companies in each industry varies and may not be sorted like this example.

 

Can anyone help? Thank you very much! 🙂

 

ISINNAMEICBSUNICBSUCEVEBITDAEV/EBITDAPeer Multiple
US7163821066PETMED EXPRESSPersonal Care, Drug and Grocery Stores452010479179559158,569775552 
US58155Q1031MCKESSONPersonal Care, Drug and Grocery Stores45201022314940164600013,55707169 
US1266501006CVS HEALTHPersonal Care, Drug and Grocery Stores45201096725580674300014,34459143 
US03073E1055AMERISOURCEBERGENPersonal Care, Drug and Grocery Stores4520101586341019090308,309670356 
US9314271084WALGREENS BOOTS ALLIANCEPersonal Care, Drug and Grocery Stores4520106505927682930007,845083323 
US1475281036CASEY'S GENERAL STORESPersonal Care, Drug and Grocery Stores45201047250764879309,683921874 
US5010441013KROGERPersonal Care, Drug and Grocery Stores4520102284412052290004,368735896 
US8718291078SYSCOPersonal Care, Drug and Grocery Stores45201032623406304724710,70586205 
US9111631035UNITED NATURAL FOODSPersonal Care, Drug and Grocery Stores4520105338523168471,684888921 
US1630861011CHEFS' WAREHOUSEPersonal Care, Drug and Grocery Stores45201011563317079516,33351225 
US85208M1027SPROUTS FARMERS MARKETPersonal Care, Drug and Grocery Stores45201022744703349316,790861401 
US8472151005SPARTANNASHPersonal Care, Drug and Grocery Stores4520105176381553713,331625593 
US92240M1080VECTOR GROUPTobacco45103019828572877006,892099409 
US02209S1033ALTRIA GROUPTobacco4510309273185993750009,891398293 
US9134561094UNIVERSALTobacco45103013499992080096,490098986 
US2186811046CORE MARK HOLDINGTobacco45103012266421331009,2159429 
US7181721090PHILIP MORRIS INTL.Tobacco4510301323910771251500010,57859185 
US0394831020ARCHER DANIELS MIDLANDFood Producers4510202581695028470009,068124341 
US4571871023INGREDIONFood Producers45102062106859490006,544452055 
US1344291091CAMPBELL SOUPFood Producers451020992999088500011,22032768 
US2058871029CONAGRA BRANDSFood Producers451020834810712943006,449901105 
US2372661015DARLING INGREDIENTSFood Producers451020459880536636712,55245423 
US90328M1071USANA HEALTH SCIENCESFood Producers45102017010002083898,162618948 
US3703341046GENERAL MILLSFood Producers4510202309531431398007,355664055 
5 REPLIES 5
PaigeMiller
Diamond | Level 26

So let's start by referring to this example at Wikipedia of the harmonic mean of three numbers.

 

Here's an outline of how to do this:

You want the sum of the reciprocals of all of the values. You can get this by groups, by first computing the inverse of the ev_ebitda in a SAS data step and them summing these inverses by group using PROC SUMMARY. This will give you the denominator of the entire group harmonic mean, the numerator is of course N for each group. Next, to adjust the harmonic mean by removing one row at a time, again in a SAS data set, you can compute the numerator as N-1 and the denominator as the denominator of the group harmonic mean computed above MINUS the inverse of ev_ebitda for this one row.

--
Paige Miller
tim-hahn
Fluorite | Level 6

Thank you very much @PaigeMiller .

 

my code now looks like this.

 

data work.Sas_test;
set work.Sas_test;
EV/EBITDA=EV/EBITDA;
run;
 
data work.Sas_test;
set work.Sas_test;
KReciprocal=1/EV/EBITDA;
run;
 
However I am stuck at the point where I group the reciprocals by industry to get the denominator.
 
data work.Sas_test;
set work.Sas_test;
if ICBSUC = 201030 then NEW=....
run;
 
do you have any suggestions to finish the code?
PaigeMiller
Diamond | Level 26

Let's back up. You can't have code EV/EBITDA=EV/EBITDA; because variable names can't have a slash in the name (and even if you could, this statement is meaningless and doesn't do anything). Run the code, get it working, then show us where you get stuck.

--
Paige Miller
tim-hahn
Fluorite | Level 6
its just a name as I named it in the excel file one could just call it Multiple

data work.Sas_test;
set work.Sas_test;
Multiple=EV/EBITDA;
run;

data work.Sas_test;
set work.Sas_test;
KReciprocal=1/Multiple;
run;
PaigeMiller
Diamond | Level 26

UNTESTED CODE, assumes sas_test is sorted by icbsuc

 

data work.Sas_test;
    set work.Sas_test;
    inverse=EBITDA/EV;
run;
proc summary data=sas_test nway;
    class icbsuc;
    var inverse;
    output out=sum_inverse sum=sum_inverse n=n;
run;
data want;
    merge sas_test sum_inverse;
    by icbsuc;
    peer_multiple = (n-1) / (sum_inverse - inverse);
run;

 

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 897 views
  • 1 like
  • 2 in conversation