<?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: Calculated columns - compare to reference period in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculated-columns-compare-to-reference-period/m-p/752083#M236852</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321775"&gt;@Chris_LK_87&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.year, a.month, abs(sales-refsales) as diff_num from
  have(where=(year&amp;gt;='2020')) a
  left join
  (select month, avg(sales) as refsales
   from have(where=('2017'&amp;lt;=year&amp;lt;='2019'))
   group by month) b
  on a.month=b.month
order by input(cats(month,year),monyy7.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 05 Jul 2021 13:01:06 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-07-05T13:01:06Z</dc:date>
    <item>
      <title>Calculated columns - compare to reference period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculated-columns-compare-to-reference-period/m-p/752070#M236846</link>
      <description>&lt;P&gt;I have a dataset that is sorted in years and months. Se data have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;;&lt;BR /&gt;input Year$ month$ sales;&lt;BR /&gt;datalines;&lt;BR /&gt;2017 Jan 10&lt;BR /&gt;2017 Feb 20 &lt;BR /&gt;2018 Jan 20 &lt;BR /&gt;2018 Feb 25 &lt;BR /&gt;2019 Jan 15&lt;BR /&gt;2019 Feb 30&lt;BR /&gt;2020 Jan 50&lt;BR /&gt;2020 Feb 40&lt;BR /&gt;2021 Jan 20&lt;BR /&gt;2021 Feb 35&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to compare against a reference period. The reference period is the average of the years 2017, 2018 and 2019 sorted for each month. The reference period is calculated like this:&amp;nbsp; (2017+2018+2019)/3 for each month. I would like to compare the years 2020 and 2021 to reference period. The comparison should have difference absolute number&lt;/P&gt;
&lt;P&gt;This is what I want my table to look like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;Year$ Month diff_num;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2020 jan 35&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2020 feb 15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2021 jan 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2021 feb 10&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 12:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculated-columns-compare-to-reference-period/m-p/752070#M236846</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2021-07-05T12:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated columns - compare to reference period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculated-columns-compare-to-reference-period/m-p/752083#M236852</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321775"&gt;@Chris_LK_87&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.year, a.month, abs(sales-refsales) as diff_num from
  have(where=(year&amp;gt;='2020')) a
  left join
  (select month, avg(sales) as refsales
   from have(where=('2017'&amp;lt;=year&amp;lt;='2019'))
   group by month) b
  on a.month=b.month
order by input(cats(month,year),monyy7.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Jul 2021 13:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculated-columns-compare-to-reference-period/m-p/752083#M236852</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-05T13:01:06Z</dc:date>
    </item>
  </channel>
</rss>

