<?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: Computing Percentage Changes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333411#M75120</link>
    <description>&lt;P&gt;You will have to describe WHY you consider some of the results "errors".&lt;/P&gt;
&lt;P&gt;whith prior=-4 and current = -2 then your formula resolves to:&lt;/P&gt;
&lt;P&gt;-2 - (-4) = 2&lt;/P&gt;
&lt;P&gt;2/ -4 = -0.5&lt;/P&gt;
&lt;P&gt;-0.5*100 = -50&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the -50% is correct from your formula. So either your formula is incorrect or&amp;nbsp;your belief that the value is incorrect is wrong or you have not completely stated the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an aside, there is a companion function to LAG called DIF that is the equivalent of Var -&amp;nbsp; lag(var). So you can use Dif(var).&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2017 15:12:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-02-16T15:12:18Z</dc:date>
    <item>
      <title>Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333373#M75102</link>
      <description>&lt;P&gt;I have an economic data series of positive and negative numbers and i am having difficulty computing the percentage change. &amp;nbsp;I &amp;nbsp;compute percentage change as: &amp;nbsp;[(current - prior)/prior]*100 &amp;nbsp; &amp;nbsp;(I am using the lag function for prior). &amp;nbsp; This works fine if the numbers are positive but errors occur in some cases with 2 negative numbers or a positive and a negative number. &amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior &amp;nbsp;4&lt;/P&gt;&lt;P&gt;current 2 &amp;nbsp; &amp;nbsp; -50% &amp;nbsp;OK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior 2&lt;/P&gt;&lt;P&gt;current 4 &amp;nbsp; &amp;nbsp; 100% &amp;nbsp;OK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior -4&lt;/P&gt;&lt;P&gt;current -2 &amp;nbsp; &amp;nbsp;- 50% error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior -2&lt;/P&gt;&lt;P&gt;current -4 &amp;nbsp; &amp;nbsp; 100% error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior 4&lt;/P&gt;&lt;P&gt;current -2 &amp;nbsp; &amp;nbsp;-150% &amp;nbsp;OK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior -4&lt;/P&gt;&lt;P&gt;current 2 &amp;nbsp; &amp;nbsp;-150% &amp;nbsp;error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior 2&lt;/P&gt;&lt;P&gt;current -4 &amp;nbsp; -300% &amp;nbsp;OK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prior -2&lt;/P&gt;&lt;P&gt;current 4 &amp;nbsp; -300% &amp;nbsp;error &amp;nbsp;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 13:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333373#M75102</guid>
      <dc:creator>rfortin</dc:creator>
      <dc:date>2017-02-16T13:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333375#M75103</link>
      <description>Can you please provide an example dataset (in the form of a data step with datalines) and the program you used with a copy of the error message ?</description>
      <pubDate>Thu, 16 Feb 2017 14:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333375#M75103</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-02-16T14:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333382#M75107</link>
      <description>&lt;P&gt;Look at proc expand for creating the new variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 14:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333382#M75107</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-16T14:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333390#M75111</link>
      <description>&lt;P&gt;Could you post your code? I've tried this example and it works fine:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;23         data _null_ ;
24           prior = -2 ;
25           current = -4 ;
26           dif = ((current - prior)/prior)*100 ;
27           put dif= ;
28         run ;

dif=100
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 14:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333390#M75111</guid>
      <dc:creator>ThierryHerrie</dc:creator>
      <dc:date>2017-02-16T14:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333411#M75120</link>
      <description>&lt;P&gt;You will have to describe WHY you consider some of the results "errors".&lt;/P&gt;
&lt;P&gt;whith prior=-4 and current = -2 then your formula resolves to:&lt;/P&gt;
&lt;P&gt;-2 - (-4) = 2&lt;/P&gt;
&lt;P&gt;2/ -4 = -0.5&lt;/P&gt;
&lt;P&gt;-0.5*100 = -50&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the -50% is correct from your formula. So either your formula is incorrect or&amp;nbsp;your belief that the value is incorrect is wrong or you have not completely stated the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an aside, there is a companion function to LAG called DIF that is the equivalent of Var -&amp;nbsp; lag(var). So you can use Dif(var).&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 15:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333411#M75120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-16T15:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333416#M75123</link>
      <description>&lt;P&gt;I think you are concerned about the sign of the pct. From -4 to -2 you get -50%, but I think you want +50%.&amp;nbsp; I.e. you want the direction of the change to determine sign of pct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; series;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; input&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; current @@;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; pct= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;*sign(dif(current))*abs(dif(current)/lag(current));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; -2&amp;nbsp;&amp;nbsp;&amp;nbsp; -4&amp;nbsp;&amp;nbsp;&amp;nbsp; -2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; -4&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 15:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333416#M75123</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-16T15:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Computing Percentage Changes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333480#M75138</link>
      <description>&lt;P&gt;Yes, this is exactly what I wanted to do. &amp;nbsp;(&amp;nbsp;&lt;SPAN&gt;I.e. you want the direction of the change to determine sign of pct.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help. &amp;nbsp; rfortin&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 17:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-Percentage-Changes/m-p/333480#M75138</guid>
      <dc:creator>rfortin</dc:creator>
      <dc:date>2017-02-16T17:17:40Z</dc:date>
    </item>
  </channel>
</rss>

