<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: market-weighted industry returns excluding ith firm in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637485#M189480</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for your email!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is not working as per expectations. The number of observations are increasing by 54 times of the original, and it's computing mean of all the firms without excluding the ith firm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Sat, 04 Apr 2020 02:12:49 GMT</pubDate>
    <dc:creator>amanjot_42</dc:creator>
    <dc:date>2020-04-04T02:12:49Z</dc:date>
    <item>
      <title>market-weighted industry returns excluding ith firm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637158#M189400</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to compute market value-weighted industry returns on a daily basis (7 years data). My sample contains returns for all the firms in the universe (firm_id), returns in percentage, industry_codes and market capitalization in dollars.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firm_id&amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; market_cap($)&amp;nbsp; &amp;nbsp;returns&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;industry_code&lt;/P&gt;&lt;P&gt;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; 4500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 77&lt;/P&gt;&lt;P&gt;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; 4510&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 77&lt;/P&gt;&lt;P&gt;&amp;nbsp;................&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;88&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; 6530&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 88&lt;/P&gt;&lt;P&gt;.................&lt;/P&gt;&lt;P&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; 8530&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;.................................&lt;/P&gt;&lt;P&gt;19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/04/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; 15530&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I want to compute industry returns for 02/04/2013 as - market_cap weighted returns for firms within the same industry_code but excluding the ith firm. For instance, industry returns for a firm coded 11 will be computed as (-6+4)/2 for 02/04/2013.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amanjot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 04:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637158#M189400</guid>
      <dc:creator>amanjot_42</dc:creator>
      <dc:date>2020-04-03T04:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: market-weighted industry returns excluding ith firm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637193#M189419</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do you mean something like below?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Firm_id date : ddmmyy10. market_cap returns industry_code;
  format date ddmmyyc10. market_cap dollar12.2;
cards4;
11 02/04/2013 4500 1.8 77
11           03/04/2013      4510                   -1                77
12          02/04/2013       6500                  2.5               88
12           03/04/2013      6530                   6                88
15          02/04/2013       8500                  -6               77
15           03/04/2013      8530                   3               77
19          02/04/2013       15500                 4               77
19           03/04/2013      15530                -4               77
;;;;
run;

proc sql;
create table want as
select 
  a.industry_code
, a.Firm_id
, a.date
, mean(b.returns) as marketValWghtdIndReturns
from
  have as a
  join
  have as b
  on 
  a.industry_code = b.industry_code
  and
  a.date = b.date
  and
  a.Firm_id ne b.Firm_id
group by 
  a.industry_code
, a.Firm_id
, a.date
order by
  a.industry_code
, a.Firm_id
, a.date
;
quit;
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 10:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637193#M189419</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-03T10:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: market-weighted industry returns excluding ith firm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637485#M189480</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for your email!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is not working as per expectations. The number of observations are increasing by 54 times of the original, and it's computing mean of all the firms without excluding the ith firm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2020 02:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637485#M189480</guid>
      <dc:creator>amanjot_42</dc:creator>
      <dc:date>2020-04-04T02:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: market-weighted industry returns excluding ith firm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637517#M189490</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Are there any additional assumptions on the data? Maybe I misunderstood your goal?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the example data you provided results is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
                                        market
                                       ValWghtd
industry_                                Ind
   code      Firm_id          date     Returns

    77          11      02:04:2013       -1.0 /* for id=11 take data from Apr 2nd from id 15 and 19: (-6+2)/2 */
    77          11      03:04:2013       -0.5 /* for id=11 take data from Apr 3rd from id 15 and 19: (3+(-4))/2 */
    77          15      02:04:2013        2.9 /* ... */
    77          15      03:04:2013       -2.5
    77          19      02:04:2013       -2.1
    77          19      03:04:2013        1.0
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should it be different ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2020 08:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637517#M189490</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-04T08:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: market-weighted industry returns excluding ith firm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637642#M189539</link>
      <description>&lt;P&gt;I suggest you get industry totals via proc summary, as that's what it is mean for.&lt;/P&gt;
&lt;P&gt;Then use the output of proc summary (data set need below) in combination with the original data set to get what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have noprint nway;
  class date ind;
  var ret
  weight mktcap;
  output out=need sum=_wgted_total  sumwgt=_total_wgt;
run;

%let min_ind=10;
%let max_ind=90;
%let begdate=01jan2013;
%let enddate=31dec2019;

data want (drop=_:);
  set need (in=inneed)
      have (in=inhave);
  array wgtsum {&amp;amp;min_ind:&amp;amp;max_ind,%sysevalf("&amp;amp;begdate"d):%sysevalf("&amp;amp;enddate"d)} _temporary_;
  array sumwgt {&amp;amp;min_ind:&amp;amp;max_ind,%sysevalf("&amp;amp;begdate"d):%sysevalf("&amp;amp;enddate"d)} _temporary_;
  array freq   {&amp;amp;min_ind:&amp;amp;max_ind,%sysevalf("&amp;amp;begdate"d):%sysevalf("&amp;amp;enddate"d)} _temporary_;	
  if inneed then do;
    wgtsum{ind,date}=_wgted_total;
	sumwgt{ind,date}=_total_wgt;
	freq{ind,date}=_freq_;
  end;
  if inhave=1;
  industry_ret=wgtsum{ind,date}/sumwgt{ind,date};
  if freq{ind,date}&amp;gt;1 then 
    indret_except_this_firm= (wgtsum{ind,date}-msrp*weight)/(sumwgt{ind,date}-weight);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The proc summary code says to classify the statistics by DATE and IND.&amp;nbsp; The variable to be "summarized" is RET, weighted by MKTCAP.&amp;nbsp; You can specify many statistics to be put in the output data set.&amp;nbsp; Here I've requested only the weighted sum of RET,&amp;nbsp; and the sum of the weights.&amp;nbsp; I.e. the numerator and denominator of RET for each DATE*IND combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the middle section set the macro variables to known upper and lower limints of industry code, and date range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the DATA WNAT step merely sticks the summary output into 2-way matrices.&amp;nbsp; These are then used when HAVE is re-read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program is untested, since you haven't provided a sample data set in sas data step form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 03:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/market-weighted-industry-returns-excluding-ith-firm/m-p/637642#M189539</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-04-05T03:14:51Z</dc:date>
    </item>
  </channel>
</rss>

