<?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: Percent change in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697783#M213312</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data WANT;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; set HAVE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; by GROUP&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; PCT = divide(-dif(VALUE),lag(VALUE)) * last.GROUP * 100;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Nov 2020 02:04:07 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-11-10T02:04:07Z</dc:date>
    <item>
      <title>Percent change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697781#M213311</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I have this sample table.&lt;/P&gt;
&lt;TABLE border="1" width="47.66930518909411%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;Group&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;Type&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;Value&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;a&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;16&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;b&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;2&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;a&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;2&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;b&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;14&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;3&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;a&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="17.414248021108182%" height="30px" class="lia-align-center"&gt;3&lt;/TD&gt;
&lt;TD width="14.863676341248905%" height="30px" class="lia-align-center"&gt;b&lt;/TD&gt;
&lt;TD width="15.39138082673702%" height="30px" class="lia-align-center"&gt;31&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate the percentage change from a to b per group. For example formula for Group 1 = (16-25)/16 * 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yoyong&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 01:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697781#M213311</guid>
      <dc:creator>yoyong555</dc:creator>
      <dc:date>2020-11-10T01:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Percent change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697783#M213312</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data WANT;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; set HAVE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; by GROUP&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; PCT = divide(-dif(VALUE),lag(VALUE)) * last.GROUP * 100;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 02:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697783#M213312</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-10T02:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Percent change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697784#M213313</link>
      <description>&lt;P&gt;Or:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data WANT;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; set HAVE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; PCT = divide(-dif(VALUE),lag(VALUE)) * (TYPE='b') * 100;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 02:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697784#M213313</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-10T02:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Percent change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697786#M213314</link>
      <description>&lt;P&gt;Thanks. How will the formula look like if it is from b to a?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 02:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697786#M213314</guid>
      <dc:creator>yoyong555</dc:creator>
      <dc:date>2020-11-10T02:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Percent change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697788#M213316</link>
      <description>&lt;P&gt;Your data is sorted by TYPE, and both code snippets take advantage of this.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 03:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697788#M213316</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-10T03:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Percent change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697809#M213328</link>
      <description>&lt;P&gt;Even if the data are sorted by group, but not always sorted by type within group, a use of the WHERE dataset name parameter in a SET statement can address the problem without doing a sort:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE (where=(type='a')
      have (where=(type='b');
  by group;
  pctchnge1=ifn(type='b',divide(dif(value),lag(value)),.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The BY statement tells SAS that the data are sorted by group.&amp;nbsp; But the SET statement forces the type a's to alway precede the type b's within a group, regardless of how they are actually ordered.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you want the pct change from b to a instead of a to b, you can do one of these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;swap the order of the where filters in the SET statement, and change the first argument of the IFN function to type='a'.&lt;BR /&gt;&amp;nbsp; or&lt;/LI&gt;
&lt;LI&gt;Leave all of them in place and, using algebra, add a statement:&lt;BR /&gt;&amp;nbsp; pctchnge2=1/(1+pctchnge1)-1;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note this assumes that each group has exactly one type a and one type b record, but ignores other types.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 06:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-change/m-p/697809#M213328</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-10T06:35:05Z</dc:date>
    </item>
  </channel>
</rss>

