<?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: how to calculate Price Growth Persistence ratio in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667102#M199709</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  ID=1;
  D='03mar2010'd; V=.63; output;
  D='03mar2011'd; V=.44; output;
  D='03mar2012'd; V=.13; output;
  D='03mar2013'd; V=.78; output;
  D='03mar2014'd; V=.27; output;
  D='03mar2015'd; V=.05; output;
  D='03mar2016'd; V=.69; output;
  D='03mar2017'd; V=.98; output;
  D='03mar2018'd; V=.72; output;
  D='03mar2019'd; V=.89; output;
  ID=2;
  D='03mar2010'd; V=.0; output;
  D='03mar2011'd; V=.1; output;
  D='03mar2012'd; V=.2; output;
  D='03mar2013'd; V=.3; output;
  D='03mar2014'd; V=.4; output;
  D='03mar2015'd; V=.5; output;
  D='03mar2016'd; V=.6; output;
  D='03mar2017'd; V=.7; output;
  D='03mar2018'd; V=.8; output;
  D='03mar2019'd; V=.9; output;
run;

data WANT;
  array _V[10] _temporary_;
  set HAVE;
  by ID;
  if first.ID then call missing(N,SUM);
  N+1;
  _V[N]=V;
  if last.ID then do;
    do FROM= 1 to N-1;
      do TO= FROM to N;
        SUM + (_V[FROM] &amp;lt; _V[TO]);     
      end;
    end; 
    output;
    putlog N= SUM=;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;N=10 SUM=30&lt;BR /&gt;N=10 SUM=45&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 05:37:15 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-07-06T05:37:15Z</dc:date>
    <item>
      <title>how to calculate Price Growth Persistence ratio in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667081#M199700</link>
      <description>&lt;DIV class="post-info"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/how-to-calculate-price-growth-persistence-ratio-using-SAS/td-p/667078" target="_blank" rel="noopener"&gt;&lt;SPAN class="message-date-friendly"&gt;Posted 2 seconds ago&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN class="message-date-views"&gt;(0 views)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am new to SAS and I have a project where I need to calculate the price growth persistence ratio. it is a little bit complex so I will try my best to be clear. Here are the details:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; 1. I have 1000 stocks and each stock has 3~10 years of data. I have calculated the annual relative price for each stock.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; 2. I need to take&amp;nbsp;each of the 10 years ( I will use 10 years as an example, but not every stock has 10 years of data) as a “base year”, count the number of subsequent years that the average relative price is higher than the base year.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; 3. Sum the 10 counts. The max count is 45, meaning every year was higher than the base year and the minimum is 0, meaning every year was lower than the base year.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; 4.&amp;nbsp;Divide the sum by the total possible count (which is 45 in this example) to get a ratio.&lt;/P&gt;&lt;P&gt;I am attaching&amp;nbsp;an example that I did in excel. But calculating the ratio for 1000 stocks really got me stumped. Any help would be greatly appreciated. Thanks.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11111.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46925iF20333F241E91EE2/image-size/large?v=v2&amp;amp;px=999" role="button" title="11111.png" alt="11111.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Jul 2020 01:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667081#M199700</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-06T01:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate Price Growth Persistence ratio in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667102#M199709</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  ID=1;
  D='03mar2010'd; V=.63; output;
  D='03mar2011'd; V=.44; output;
  D='03mar2012'd; V=.13; output;
  D='03mar2013'd; V=.78; output;
  D='03mar2014'd; V=.27; output;
  D='03mar2015'd; V=.05; output;
  D='03mar2016'd; V=.69; output;
  D='03mar2017'd; V=.98; output;
  D='03mar2018'd; V=.72; output;
  D='03mar2019'd; V=.89; output;
  ID=2;
  D='03mar2010'd; V=.0; output;
  D='03mar2011'd; V=.1; output;
  D='03mar2012'd; V=.2; output;
  D='03mar2013'd; V=.3; output;
  D='03mar2014'd; V=.4; output;
  D='03mar2015'd; V=.5; output;
  D='03mar2016'd; V=.6; output;
  D='03mar2017'd; V=.7; output;
  D='03mar2018'd; V=.8; output;
  D='03mar2019'd; V=.9; output;
run;

data WANT;
  array _V[10] _temporary_;
  set HAVE;
  by ID;
  if first.ID then call missing(N,SUM);
  N+1;
  _V[N]=V;
  if last.ID then do;
    do FROM= 1 to N-1;
      do TO= FROM to N;
        SUM + (_V[FROM] &amp;lt; _V[TO]);     
      end;
    end; 
    output;
    putlog N= SUM=;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;N=10 SUM=30&lt;BR /&gt;N=10 SUM=45&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 05:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667102#M199709</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-06T05:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate Price Growth Persistence ratio in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667117#M199718</link>
      <description>&lt;P&gt;I made a couple of changes to the code supplied by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Using a DoW loop (looping with DO UNTIL(LAST.ID)) makes the code simpler&lt;/LI&gt;
&lt;LI&gt;I increased the array length, just in case there were shares with more than 10 years - in which case you will get the number for all the years.&lt;/LI&gt;
&lt;LI&gt;I put the code to calculate count inside the loop that reads the data, simpler and more efficient.&lt;/LI&gt;
&lt;LI&gt;I added the calculation of the possible max and the PGP ratio.&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array values(100) 8 _temporary_; /* the array is longer, just in case some shares have more than 10 years */
  count=0;
  do years=1 by 1 until(last.ID);
    set have;
    by ID;
    values(years)=V;
    do i=1 to years-1;
      count+(values(i)&amp;lt;values(years));
      end;
    end;
  max=years*(years-1)/2;
  PGP_Ratio=count/max;
  keep ID years count PGP_ratio;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This datastep assumes the input to be sorted by ID and ascending YEAR.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 08:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667117#M199718</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-07-06T08:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate Price Growth Persistence ratio in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667126#M199721</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;Using a DoW loop (looping with DO UNTIL(LAST.ID)) makes the code simpler&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's definitely a matter of opinion. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 08:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667126#M199721</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-06T08:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate Price Growth Persistence ratio in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667337#M199807</link>
      <description>&lt;P&gt;Thank you very much! Your code works perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 01:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667337#M199807</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-07T01:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate Price Growth Persistence ratio in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667339#M199809</link>
      <description>&lt;P&gt;Thank you for your reply! Although it is not exactly what I wanted but it does help a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 01:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-Price-Growth-Persistence-ratio-in-SAS/m-p/667339#M199809</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-07T01:40:02Z</dc:date>
    </item>
  </channel>
</rss>

