<?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: Need SAS code for organizing and finding percentage in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618225#M181329</link>
    <description>&lt;P&gt;&lt;STRONG&gt;"SAS coding for Finance student"---&amp;nbsp;&lt;/STRONG&gt;My oh my!, those words seem scary and intimidating. I just do SAS like&amp;nbsp; video games and that's as far as it goes. My recommendation would be to read anything/all posts by&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; &amp;nbsp;World's renowned super star who is also known as Paul Dorfman aka Don of the SAS world and a SAS author&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp; King of SAS, with a prefix John&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;Kolmogorov reborn - This man is prolly your best bet to offer advice&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; The sage who transcends generations&lt;/P&gt;
&lt;P&gt;5.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;My mother's favorite&lt;/P&gt;
&lt;P&gt;6.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; There isn't a thing&amp;nbsp; that Reeza doesn't know about&lt;/P&gt;
&lt;P&gt;7.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; The statsman -champion of Regression,&lt;EM&gt;Canonical correlation analysis etc&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;8. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; The champ of manipulating time series without using INTERVALDS, can custom code anything he likes&lt;/P&gt;
&lt;P&gt;9.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; With him you will never LAG and will always LEAD plus you would SET things conditionally&lt;/P&gt;
&lt;P&gt;10.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; First and last captures the heart, and at last Prodigy Genius stats&amp;nbsp; aka Pierre has no Peers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please reach out to them and hopefully you get started. All the best bro! Have fun learning!&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;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much. Could you give me a video link from which I can learn necessary SAS coding for Finance student&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jan 2020 00:08:10 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-18T00:08:10Z</dc:date>
    <item>
      <title>Need SAS code for organizing and finding percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618192#M181311</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Rank&lt;/TD&gt;&lt;TD&gt;TDC1&lt;/TD&gt;&lt;TD&gt;GVKEY&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Percentage of TDC1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5237.743&lt;/TD&gt;&lt;TD&gt;1004&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;0.4265&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2554.467&lt;/TD&gt;&lt;TD&gt;1004&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1578.104&lt;/TD&gt;&lt;TD&gt;1004&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1314.079&lt;/TD&gt;&lt;TD&gt;1004&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1596.902&lt;/TD&gt;&lt;TD&gt;1004&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;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t;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5231.393&lt;/TD&gt;&lt;TD&gt;1045&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;0.3532&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2372.14&lt;/TD&gt;&lt;TD&gt;1045&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1776.069&lt;/TD&gt;&lt;TD&gt;1045&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2288.908&lt;/TD&gt;&lt;TD&gt;1045&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3142.082&lt;/TD&gt;&lt;TD&gt;1045&lt;/TD&gt;&lt;TD&gt;2010&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, I need help for the following.&lt;/P&gt;&lt;P&gt;1. The ranks in the above data are created based on the TDC1. There should be 5 TDC1 observations based on each year. But if you look at 2011, it misses one observation. So, I want to delete all the observations in that year. I have a huge data set. In that data set, if I have less than 5 TDC1 observations in each year or GVKEY, I have to remove all the observations for that particular year and GVKEY. I want to be consistent throughout so that I will have 5 TDC1 observations for each year for different GVKEY. Can anyone please help me by giving me SAS code for that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I need to find the percentage of TDC1 for each year and for Rank 1. An example is given in the last column above.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the percentage for the first row is (5237.743/(5237.743+2554.467+1578.104+1314.079+1596.902).&amp;nbsp; Please give me SAS code for this too.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2020 20:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618192#M181311</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-01-17T20:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS code for organizing and finding percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618193#M181312</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp; Straight forward SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Rank	TDC1	GVKEY	Year;*	PercentageofTDC1;
cards;
1	5237.743	1004	2010	0.4265
2	2554.467	1004	2010	 
3	1578.104	1004	2010	 
5	1314.079	1004	2010	 
4	1596.902	1004	2010	 
1	5786.4	1004	2011	 
2	2781.156	1004	2011	 
4	1696.431	1004	2011	 
3	1727.069	1004	2011	 
1	4182.832	1004	2012	0.4386
2	2068.554	1004	2012	 
5	841.204	1004	2012	 
3	1312.852	1004	2012	 
4	1131.176	1004	2012	 
1	3700.925	1013	2010	0.4832
2	1099.786	1013	2010	 
5	848.657	1013	2010	 
3	1067.566	1013	2010	 
4	941.748	1013	2010	 
1	5231.393	1045	2010	0.3532
4	2372.14	1045	2010	 
5	1776.069	1045	2010	 
3	2288.908	1045	2010	 
2	3142.082	1045	2010	 
;


proc sql;
create table want as
select *,ifn(rank=1,TDC1/sum(TDC1),.) as Pct
from have
group by GVKEY,Year
having count(*)=5
order by GVKEY,year,rank;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jan 2020 20:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618193#M181312</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-17T20:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS code for organizing and finding percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618222#M181327</link>
      <description>&lt;P&gt;Thank you very much. Could you give me a video link from which I can learn necessary SAS coding for Finance student&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2020 23:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618222#M181327</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-01-17T23:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS code for organizing and finding percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618225#M181329</link>
      <description>&lt;P&gt;&lt;STRONG&gt;"SAS coding for Finance student"---&amp;nbsp;&lt;/STRONG&gt;My oh my!, those words seem scary and intimidating. I just do SAS like&amp;nbsp; video games and that's as far as it goes. My recommendation would be to read anything/all posts by&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; &amp;nbsp;World's renowned super star who is also known as Paul Dorfman aka Don of the SAS world and a SAS author&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp; King of SAS, with a prefix John&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;Kolmogorov reborn - This man is prolly your best bet to offer advice&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; The sage who transcends generations&lt;/P&gt;
&lt;P&gt;5.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;My mother's favorite&lt;/P&gt;
&lt;P&gt;6.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; There isn't a thing&amp;nbsp; that Reeza doesn't know about&lt;/P&gt;
&lt;P&gt;7.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; The statsman -champion of Regression,&lt;EM&gt;Canonical correlation analysis etc&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;8. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; The champ of manipulating time series without using INTERVALDS, can custom code anything he likes&lt;/P&gt;
&lt;P&gt;9.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; With him you will never LAG and will always LEAD plus you would SET things conditionally&lt;/P&gt;
&lt;P&gt;10.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; First and last captures the heart, and at last Prodigy Genius stats&amp;nbsp; aka Pierre has no Peers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please reach out to them and hopefully you get started. All the best bro! Have fun learning!&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;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much. Could you give me a video link from which I can learn necessary SAS coding for Finance student&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2020 00:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618225#M181329</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-18T00:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS code for organizing and finding percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618231#M181331</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Assuming that the input is sorted by [gvkey,year], you can interleave the files by this key. Then in the first pass through each BY group do the summation and in the second pass decide whether to keep the group and if yes, compute the percentage for the record with rank=1.&lt;/P&gt;
&lt;P&gt;In SAS words:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  input rank tdc1 gvkey year ;                                                                                                          
cards ;                                                                                                                                 
1  5237.743  1004  2010                                                                                                                 
2  2554.467  1004  2010                                                                                                                 
3  1578.104  1004  2010                                                                                                                 
5  1314.079  1004  2010                                                                                                                 
4  1596.902  1004  2010                                                                                                                 
1  5786.4    1004  2011                                                                                                                 
2  2781.156  1004  2011                                                                                                                 
4  1696.431  1004  2011                                                                                                                 
3  1727.069  1004  2011                                                                                                                 
1  4182.832  1004  2012                                                                                                                 
2  2068.554  1004  2012                                                                                                                 
5   841.204  1004  2012                                                                                                                 
3  1312.852  1004  2012                                                                                                                 
4  1131.176  1004  2012                                                                                                                 
1  3700.925  1013  2010                                                                                                                 
2  1099.786  1013  2010                                                                                                                 
5   848.657  1013  2010                                                                                                                 
3  1067.566  1013  2010                                                                                                                 
4   941.748  1013  2010                                                                                                                 
1  5231.393  1045  2010                                                                                                                 
4  2372.14   1045  2010                                                                                                                 
5  1776.069  1045  2010                                                                                                                 
3  2288.908  1045  2010                                                                                                                 
2  3142.082  1045  2010                                                                                                                 
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want (drop = _:) ;                                                                                                                 
  set have (in=h) have ;                                                                                                                
  by gvkey year ;                                                                                                                       
  if h then do ;                                                                                                                        
    if first.year then call missing (_s, _n) ;                                                                                          
    _s + tdc1 ;                                                                                                                         
    _n + 1 ;                                                                                                                            
  end ;                                                                                                                                 
  else if _n = 5 then do ;                                                                                                              
    if rank = 1 then tdc1_pct = divide (tdc1, _s) ;                                                                                     
    output ;                                                                                                                            
  end ;                                                                                                                                 
run ;                                                  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2020 00:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618231#M181331</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2020-01-18T00:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need SAS code for organizing and finding percentage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618236#M181335</link>
      <description>&lt;P&gt;Here's a slight variation on &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;'s.&amp;nbsp; It also uses SET with two HAVE's, but doesn't accumulate TDC1 in the first pass.&amp;nbsp; It retieves the TDC1 total only when PCT is calculated.&amp;nbsp; I offer this just as a specimen of a particular style (using subsetting IF to eliminate the need for an explicit OUTPUT):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Rank	TDC1	GVKEY	Year;*	PercentageofTDC1;
cards;
1	5237.743	1004	2010	0.4265
2	2554.467	1004	2010	 
3	1578.104	1004	2010	 
5	1314.079	1004	2010	 
4	1596.902	1004	2010	 
1	5786.4	1004	2011	 
2	2781.156	1004	2011	 
4	1696.431	1004	2011	 
3	1727.069	1004	2011	 
1	4182.832	1004	2012	0.4386
2	2068.554	1004	2012	 
5	841.204	1004	2012	 
3	1312.852	1004	2012	 
4	1131.176	1004	2012	 
1	3700.925	1013	2010	0.4832
2	1099.786	1013	2010	 
5	848.657	1013	2010	 
3	1067.566	1013	2010	 
4	941.748	1013	2010	 
1	5231.393	1045	2010	0.3532
4	2372.14	1045	2010	 
5	1776.069	1045	2010	 
3	2288.908	1045	2010	 
2	3142.082	1045	2010	 
;

data want;
  set have (in=firstpass) have (in=secondpass);
  by gvkey year;
  array t {5} _temporary_;
  if first.year then call missing(of t{*});
  if firstpass then t{rank}=tdc1;
  
  if secondpass=1 and n(of t{*})=5;
  if rank=1 then pct=t{1}/sum(of t{*});  
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note it doesn't protect against having extra obs for ranks 1 through 5 (i.e. it doesn't count records, it counts distinct ranks).&amp;nbsp; And it relies on data being sorted by GVKEY/YEAR (but not neccessarily RANK).&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2020 03:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-SAS-code-for-organizing-and-finding-percentage/m-p/618236#M181335</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-18T03:28:38Z</dc:date>
    </item>
  </channel>
</rss>

