<?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: Difference computation between quarters in the same company in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681234#M206041</link>
    <description>&lt;P&gt;Please post the data in usable form, being a member of the community for three years, you should know that excel-files are not usable for many other members. Also add what you expect as result using the data provided.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2020 05:33:42 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-09-03T05:33:42Z</dc:date>
    <item>
      <title>Difference computation between quarters in the same company</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681217#M206034</link>
      <description>&lt;P&gt;Dear Madam/Sir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to compute differences between quarters in the same company using the following code, but it did not work.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;GVKEY&lt;/TD&gt;&lt;TD&gt;DATADATE&lt;/TD&gt;&lt;TD&gt;FYEARQ&lt;/TD&gt;&lt;TD&gt;FQTR&lt;/TD&gt;&lt;TD&gt;saley&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1004&lt;/TD&gt;&lt;TD&gt;19850831&lt;/TD&gt;&lt;TD&gt;1985&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;53.836&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1004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t;/TABLE&gt;&lt;P&gt;1st Quarter saleq = 1st Quarter saley&lt;BR /&gt;2nd Quarter saleq = 2nd Quarter saley - 1st Quarter saley&lt;BR /&gt;3rd Quarter saleq = 3rd Quarter saley - 2nd Quarter saley&lt;BR /&gt;4th Quarter saleq = 4th Quarter saley- 3rd Quarter saley&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a5; set a4;&lt;BR /&gt;by fyearq;&lt;BR /&gt;if fqtr=1 then cf1=saley;&lt;BR /&gt;if fqtr=2 then cf2=saley;&lt;BR /&gt;if fqtr=3 then cf3=saley;&lt;BR /&gt;if fqtr=4 then cf4=saley;&lt;BR /&gt;if fqtr=2 then saleq=cf2-cf1;&lt;BR /&gt;if fqtr=3 then saleq=cf3-cf2;&lt;BR /&gt;if fqtr=4 then saleq=cf4-cf3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be highly appreciated.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Joon1&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 04:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681217#M206034</guid>
      <dc:creator>joon1</dc:creator>
      <dc:date>2020-09-03T04:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Difference computation between quarters in the same company</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681220#M206036</link>
      <description>&lt;P&gt;Use the DIF function, defined as&amp;nbsp; DIF(x)=X-LAG(X):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a5; 
  set a4;
  saleq=dif(saley);
  if fqtr=1 then saleq=saley;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, this code requires that each GVKEY begins with FQTR=1.&amp;nbsp;&amp;nbsp; Otherwise the first record of an offending GVKEY would have values contaminated with a lagged saley value from the prior gvkey.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit note: Of course this also assumes data are sorted by gvkey/datadate.&amp;nbsp; And that there are no missing quarters.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 05:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681220#M206036</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-03T05:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Difference computation between quarters in the same company</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681234#M206041</link>
      <description>&lt;P&gt;Please post the data in usable form, being a member of the community for three years, you should know that excel-files are not usable for many other members. Also add what you expect as result using the data provided.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 05:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681234#M206041</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-03T05:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Difference computation between quarters in the same company</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681285#M206054</link>
      <description>&lt;P&gt;Try DIF with special handling of FIRST.&amp;lt;company&amp;gt;&amp;nbsp; Coding an IFN() function call ensures all arguments that are expressions will be evaluated and thus you don't need to worry about a&amp;nbsp;&lt;EM&gt;conditional&lt;/EM&gt; DIF() functional call that would compute difference from the wrong lag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;&lt;BR /&gt;  set have;&lt;BR /&gt;  by gvkey fyearq fqtr;  * only need gvkey, but other two ensures ERROR occurs if data is NOT sorted for quarter to quarter computation;&lt;BR /&gt;  sale_qdif = ifn(first.gvkey, ., dif1(saley));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 10:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681285#M206054</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-03T10:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Difference computation between quarters in the same company</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681534#M206149</link>
      <description>&lt;P&gt;Thank you so much for your help, Richard.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 22:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-computation-between-quarters-in-the-same-company/m-p/681534#M206149</guid>
      <dc:creator>joon1</dc:creator>
      <dc:date>2020-09-03T22:53:39Z</dc:date>
    </item>
  </channel>
</rss>

