<?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: the percentage of 'Firm_ID''s 'share_outstanding' held by all 'fundno' in a 'year' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799617#M314451</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is a large sample that includes a large number of firms during a&amp;nbsp;15-year period, and the funds that hold their shares. I am cleaning the data to construct the fund_ratio variable for each 'Firm_ID' in each 'year'. actually, in most cases, each group only has one 'share_outstanding' value. but, in some cases, there is more than one 'share_holding' value in a group,&lt;U&gt; I am trying to keep the most frequent 'share_holding' value in each group and delete the rest. If there is more than one most frequent 'share_holding' value in each group, then keep them together.&amp;nbsp;&amp;nbsp;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the rule is: in each group (same 'Firm_ID and same 'year'), remain the most frequent&amp;nbsp;'share_holding' value, and if there is&amp;nbsp;more than one most frequent 'share_holding' value in each group, then keep them together.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope it is more clear. could you please give me some advice about how to get the result I need.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This rule is still incomplete.&amp;nbsp; It addresses the following cases:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A single shares outstanding (SHROUT) value - output 1 record using that value.&lt;/LI&gt;
&lt;LI&gt;Multiple SHROUTs, but with a single most frequent SHROUT. - output 1 record using that valuje&lt;/LI&gt;
&lt;LI&gt;Multiple SHROUT values, all with the same frequency - output 1 record per unique SHROUT&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;But it doesn't address the case of multiple SHROUT values, with a tie for most frequent (case 3 above), but also with other less frequent SHROUTs.&amp;nbsp; For instance, say you have 2 SHROUTs at 30m, 2 at 28m, and 1 each at 29m and 31m.&amp;nbsp; What do you want in that case?&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 17:13:05 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-03-02T17:13:05Z</dc:date>
    <item>
      <title>the percentage of 'Firm_ID''s 'share_outstanding' held by all 'fundno' in a 'year'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799489#M314382</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate the percentage of each firm (Firm_ID)’s outstanding shares (share_outstanding) held by funds (‘fundno’ for fund id; and ‘shares’ is the number of firm’s shares held by a fund in a year) in each year (year).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is, although in most cases, each group (i.e., each ‘Firm_ID’ in each ‘year’) only has one ‘share_outstanding’ value, in some cases a group includes more than one ‘share_outstanding’ value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By following Table1 as an example,&lt;/P&gt;&lt;PRE&gt;data table1;
infile cards dsd dlm=",";
input
firm_id :$15.
year :8.
fundno :$15.
shares :8.
share_outstanding :8.
;
cards;
36110,2002, 14086, 18000, 32000000
36110,2002, 15056, 92000, 32000000
36110,2002, 15058, 4740, 32000000
36110,2002, 16500, 35300, 27000000

36111,2002, 1903, 26700, 32000000
36111,2002, 1909, 543350, 32000000
36111,2002, 19658, 60000, 30000000
36111,2002, 2021, 20000, 30000000
36111,2002, 2034, 59700, 32000000

36110,2003, 14086, 18000, 32000000
36110,2003, 15056, 92000, 32000000
36110,2003, 15058, 4740, 37000000
36110,2003, 16500, 35300, 27000000

36111,2003, 1903, 26700, 32000000
36111,2003, 1909, 543350, 31000000
36111,2003, 19658, 60000, 33000000
36111,2003, 2021, 20000, 30000000
;;;;
run;

&lt;/PRE&gt;&lt;P&gt;There are four groups (same Firm_iD, and same year) in Table 1. By using the first group as an example,&lt;/P&gt;&lt;P&gt;There are three ‘32000000’ and one ‘27000000’ in this group (i.e., Firm_ID=36110 and year=2002), and then&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I assume the outstanding share of Firm_ID ‘36110’ in ‘year’ 2002 is ‘32000000’.&lt;/LI&gt;&lt;LI&gt;I sum the number of shares held by funds in this group, which is 150040 (=18000+92000+4740+35300)&lt;/LI&gt;&lt;LI&gt;I divide the number of shares held by funds in this group (150040) by the firm’s outstanding shares (32000000) to get a new variable ‘fund_ratio‘, which equals 0.00468875.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;In the end, I expect to get&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Firm_ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;year&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fund_ratio&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36110&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.00468875&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following the same rule, in the second group (i.e., Firm_ID=36111 and year=2002), I have three ‘32000000’ and two ‘&lt;STRONG&gt;30000000’. So, the fund_ratio=0.0221796875, which is (26700+&lt;/STRONG&gt;543350+60000+20000+59700)/ 32000000.&amp;nbsp;I expect to get&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Firm_ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;year&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fund_ratio&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36111&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;0.0221796875&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the third (Firm_ID=36110,year=2003), there are two ‘32000000’ and two ‘37000000’. In this case, I keep them both.&amp;nbsp;I expect to get&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Firm_ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;year&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fund_ratio&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36110&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.00468875&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36110&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;0.00405514&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As&lt;/P&gt;&lt;P&gt;0.00468875= (18000+92000+4740+35300)/ 32000000&lt;/P&gt;&lt;P&gt;0.00405514= (18000+92000+4740+35300)/ 37000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fourth group (Firm_ID=36111, year=2003), I expect to get&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Firm_ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;year&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;fund_ratio&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36111&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.020314063&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36111&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.020969355&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36111&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.019698485&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;36111&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.021668333&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As&lt;/P&gt;&lt;P&gt;0.020314063 = (26700+543350+60000+ 20000)/32000000&lt;/P&gt;&lt;P&gt;0.020969355= (26700+543350+60000+ 20000)/ 31000000&lt;/P&gt;&lt;P&gt;0.019698485= (26700+543350+60000+ 20000)/ 33000000&lt;/P&gt;&lt;P&gt;0.021668333= (26700+543350+60000+ 20000)/ 30000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it is clear.&lt;/P&gt;&lt;P&gt;Many thanks in advance for any advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 04:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799489#M314382</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2022-03-02T04:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: the percentage of 'Firm_ID''s 'share_outstanding' held by all 'fundno' in a 'year'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799498#M314383</link>
      <description>&lt;P&gt;You need to provide a &lt;STRONG&gt;Rule,&lt;/STRONG&gt; or rules, for determining what the value of the denominator is for each group. Examples don't quite cover things when we get some other group that has 5 different "shares outstanding" values with 5 records for a given year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The information you have provided would allow exactly 4 groups to be calculated for two companies and two years. Do you have more years? More companies? If so, we do not have sufficient information to handle those other cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to calculate the percentage of each firm (Firm_ID)’s outstanding shares (share_outstanding) held by funds (‘fundno’ for fund id; and ‘shares’ is the number of firm’s shares held by a fund in a year) in each year (year).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My problem is, although in most cases, each group (i.e., each ‘Firm_ID’ in each ‘year’) only has one ‘share_outstanding’ value, in some cases a group includes more than one ‘share_outstanding’ value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By following Table1 as an example,&lt;/P&gt;
&lt;PRE&gt;data table1;
infile cards dsd dlm=",";
input
firm_id :$15.
year :8.
fundno :$15.
shares :8.
share_outstanding :8.
;
cards;
36110,2002, 14086, 18000, 32000000
36110,2002, 15056, 92000, 32000000
36110,2002, 15058, 4740, 32000000
36110,2002, 16500, 35300, 27000000

36111,2002, 1903, 26700, 32000000
36111,2002, 1909, 543350, 32000000
36111,2002, 19658, 60000, 30000000
36111,2002, 2021, 20000, 30000000
36111,2002, 2034, 59700, 32000000

36110,2003, 14086, 18000, 32000000
36110,2003, 15056, 92000, 32000000
36110,2003, 15058, 4740, 37000000
36110,2003, 16500, 35300, 27000000

36111,2003, 1903, 26700, 32000000
36111,2003, 1909, 543350, 31000000
36111,2003, 19658, 60000, 33000000
36111,2003, 2021, 20000, 30000000
;;;;
run;

&lt;/PRE&gt;
&lt;P&gt;There are four groups (same Firm_iD, and same year) in Table 1. By using the first group as an example,&lt;/P&gt;
&lt;P&gt;There are three ‘32000000’ and one ‘27000000’ in this group (i.e., Firm_ID=36110 and year=2002), and then&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I assume the outstanding share of Firm_ID ‘36110’ in ‘year’ 2002 is ‘32000000’.&lt;/LI&gt;
&lt;LI&gt;I sum the number of shares held by funds in this group, which is 150040 (=18000+92000+4740+35300)&lt;/LI&gt;
&lt;LI&gt;I divide the number of shares held by funds in this group (150040) by the firm’s outstanding shares (32000000) to get a new variable ‘fund_ratio‘, which equals 0.00468875.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;In the end, I expect to get&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Firm_ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;year&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;fund_ratio&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36110&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0.00468875&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following the same rule, in the second group (i.e., Firm_ID=36111 and year=2002), I have three ‘32000000’ and two ‘&lt;STRONG&gt;30000000’. So, the fund_ratio=0.0221796875, which is (26700+&lt;/STRONG&gt;543350+60000+20000+59700)/ 32000000.&amp;nbsp;I expect to get&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Firm_ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;year&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;fund_ratio&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36111&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;0.0221796875&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the third (Firm_ID=36110,year=2003), there are two ‘32000000’ and two ‘37000000’. In this case, I keep them both.&amp;nbsp;I expect to get&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Firm_ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;year&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;fund_ratio&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36110&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2003&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0.00468875&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36110&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2003&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;0.00405514&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;As&lt;/P&gt;
&lt;P&gt;0.00468875= (18000+92000+4740+35300)/ 32000000&lt;/P&gt;
&lt;P&gt;0.00405514= (18000+92000+4740+35300)/ 37000000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;fourth group (Firm_ID=36111, year=2003), I expect to get&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Firm_ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;year&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;fund_ratio&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36111&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2003&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0.020314063&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36111&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2003&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0.020969355&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36111&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2003&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0.019698485&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;36111&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2003&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0.021668333&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;As&lt;/P&gt;
&lt;P&gt;0.020314063 = (26700+543350+60000+ 20000)/32000000&lt;/P&gt;
&lt;P&gt;0.020969355= (26700+543350+60000+ 20000)/ 31000000&lt;/P&gt;
&lt;P&gt;0.019698485= (26700+543350+60000+ 20000)/ 33000000&lt;/P&gt;
&lt;P&gt;0.021668333= (26700+543350+60000+ 20000)/ 30000000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope it is clear.&lt;/P&gt;
&lt;P&gt;Many thanks in advance for any advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 04:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799498#M314383</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-02T04:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: the percentage of 'Firm_ID''s 'share_outstanding' held by all 'fundno' in a 'year'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799506#M314386</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is a large sample that includes a large number of firms during a&amp;nbsp;15-year period, and the funds that hold their shares. I am cleaning the data to construct the fund_ratio variable for each 'Firm_ID' in each 'year'. actually, in most cases, each group only has one 'share_outstanding' value. but, in some cases, there is more than one 'share_holding' value in a group,&lt;U&gt; I am trying to keep the most frequent 'share_holding' value in each group and delete the rest. If there is more than one most frequent 'share_holding' value in each group, then keep them together.&amp;nbsp;&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the rule is: in each group (same 'Firm_ID and same 'year'), remain the most frequent&amp;nbsp;'share_holding' value, and if there is&amp;nbsp;more than one most frequent 'share_holding' value in each group, then keep them together.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it is more clear. could you please give me some advice about how to get the result I need.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 05:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799506#M314386</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2022-03-02T05:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: the percentage of 'Firm_ID''s 'share_outstanding' held by all 'fundno' in a 'year'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799617#M314451</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is a large sample that includes a large number of firms during a&amp;nbsp;15-year period, and the funds that hold their shares. I am cleaning the data to construct the fund_ratio variable for each 'Firm_ID' in each 'year'. actually, in most cases, each group only has one 'share_outstanding' value. but, in some cases, there is more than one 'share_holding' value in a group,&lt;U&gt; I am trying to keep the most frequent 'share_holding' value in each group and delete the rest. If there is more than one most frequent 'share_holding' value in each group, then keep them together.&amp;nbsp;&amp;nbsp;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the rule is: in each group (same 'Firm_ID and same 'year'), remain the most frequent&amp;nbsp;'share_holding' value, and if there is&amp;nbsp;more than one most frequent 'share_holding' value in each group, then keep them together.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope it is more clear. could you please give me some advice about how to get the result I need.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This rule is still incomplete.&amp;nbsp; It addresses the following cases:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A single shares outstanding (SHROUT) value - output 1 record using that value.&lt;/LI&gt;
&lt;LI&gt;Multiple SHROUTs, but with a single most frequent SHROUT. - output 1 record using that valuje&lt;/LI&gt;
&lt;LI&gt;Multiple SHROUT values, all with the same frequency - output 1 record per unique SHROUT&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;But it doesn't address the case of multiple SHROUT values, with a tie for most frequent (case 3 above), but also with other less frequent SHROUTs.&amp;nbsp; For instance, say you have 2 SHROUTs at 30m, 2 at 28m, and 1 each at 29m and 31m.&amp;nbsp; What do you want in that case?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 17:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799617#M314451</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-02T17:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: the percentage of 'Firm_ID''s 'share_outstanding' held by all 'fundno' in a 'year'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799685#M314463</link>
      <description>&lt;P&gt;First, you have an apparent data error in the 3rd group (&lt;SPAN&gt;Firm_ID=36110,year=2003).&amp;nbsp; I think the fourth row should have share_outstanding=37000000&amp;nbsp; (you have 27000000).&amp;nbsp; With that correction, this program should do the following:&amp;nbsp; output 1 record for each share_oustanding value that has or matches the highest frequency:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
  infile cards dsd dlm=",";
  input  firm_id :$15.  year :8.  fundno :$15.  shares :8.  share_outstanding :8.  ;
cards;
36110,2002, 14086, 18000, 32000000
36110,2002, 15056, 92000, 32000000
36110,2002, 15058, 4740, 32000000
36110,2002, 16500, 35300, 27000000
36111,2002, 1903, 26700, 32000000
36111,2002, 1909, 543350, 32000000
36111,2002, 19658, 60000, 30000000
36111,2002, 2021, 20000, 30000000
36111,2002, 2034, 59700, 32000000
36110,2003, 14086, 18000, 32000000
36110,2003, 15056, 92000, 32000000
36110,2003, 15058, 4740, 37000000
36110,2003, 16500, 35300, 37000000
36111,2003, 1903, 26700, 32000000
36111,2003, 1909, 543350, 31000000
36111,2003, 19658, 60000, 33000000
36111,2003, 2021, 20000, 30000000
run;


data want (keep=firm_id year total_shares_held share_outstanding ratio);
  array shr{20};
  array frq{20};
  do until (last.year);
    set table1;
    by firm_id year notsorted;
    total_shares_held=sum(total_shares_held,shares);
    s=whichn(share_outstanding,of shr{*});
    if s=0 then do; 
      n_freqs=sum(n_freqs,1);
      shr{n_freqs}=share_outstanding; 
      s=n_freqs;
    end;
    frq{s}=sum(1,frq{s});
  end;
  max_frq=max(of frq{*});  /*Maximum frequency */

  do until (max(of frq{*})^=max_frq);
    s=whichn(max_frq,of frq{*});    /* The Sth frequency equals the MAX_FRQ */
    share_outstanding=shr{s};       /* Get the corresponding denominator */
    ratio=total_shares_held/share_outstanding;
    output;
    frq{s}=.;                      /* Blank out the Sth frq, so that ties can be found */
    if n(of frq{*})=0 then leave;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This allows for up to 20 records (actually 20 unique &lt;EM&gt;&lt;STRONG&gt;share_outstanding&lt;/STRONG&gt;&lt;/EM&gt; values) for each FIRM_ID/YEAR.&amp;nbsp; If you expect more, then increase the size of the SHR and FRQ arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How it works.&lt;BR /&gt;For each FIRM_ID/YEAR:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Read a record&lt;/LI&gt;
&lt;LI&gt;See if the share_outstanding is new (in which case&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;whichn(share_outstanding,of shr{*})&lt;/STRONG&gt;&lt;/EM&gt; returns a zero, otherwise it returns the position in the array SHR in whicih share_outstanding already appears).
&lt;OL&gt;
&lt;LI&gt;If new add the new value to the SHR array, and increment N_FREQS by 1.&amp;nbsp; And set the position index &lt;EM&gt;&lt;STRONG&gt;s&lt;/STRONG&gt;&lt;/EM&gt; to N_FREQS&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;Add 1 to &lt;EM&gt;&lt;STRONG&gt;frq{s}&lt;/STRONG&gt;&lt;/EM&gt;, keeping track of frequencies of the corresponding &lt;EM&gt;&lt;STRONG&gt;shr{s}&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/LI&gt;
&lt;LI&gt;After all the records have been read, establish &lt;EM&gt;&lt;STRONG&gt;max_frq&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;For each instance in which frg{s}=max_frq:
&lt;OL&gt;
&lt;LI&gt;Find the leftmost s, via &lt;EM&gt;&lt;STRONG&gt;whichn(max_frq,of frq{*})&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;get the corresponding &lt;STRONG&gt;shr{s},&lt;/STRONG&gt;&amp;nbsp;calculate the ratio, and output.&lt;/LI&gt;
&lt;LI&gt;Set &lt;STRONG&gt;frqs{s}&lt;/STRONG&gt; to missing, so that the next leftmost qualifying &lt;EM&gt;&lt;STRONG&gt;frq&lt;/STRONG&gt;&lt;/EM&gt; can be located.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 22:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-percentage-of-Firm-ID-s-share-outstanding-held-by-all-fundno/m-p/799685#M314463</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-02T22:29:26Z</dc:date>
    </item>
  </channel>
</rss>

