<?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: Help Request - Dataset(s) that mimic two excel pivots with slicers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874630#M345585</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;when calculating the ABS_VALUE you can not call it &lt;EM&gt;"B.ABS_VALUE"&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ABS(SUM(ActualValues) - SUM(FORECAST)) AS B.ABS_VALUE&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ABS(SUM(ActualValues) - SUM(FORECAST)) AS ABS_VALUE&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE PIVOT AS
      SELECT A.RETAILER,
             A.PRODUCT,
             A.CATEGORY,
             A.BRAND,
             A.DATE,
             SUM(A.ActualValues) AS Actuals,
             SUM(A.Forecast) AS Forecast,
             B.ABS_VALUE
      FROM WORK.DATA AS A
      LEFT JOIN
        (SELECT RETAILER,
                PRODUCT,
                CATEGORY,
                BRAND, DATE, ABS(SUM(ActualValues) - SUM(FORECAST)) AS ABS_VALUE
         FROM WORK.DATA
         GROUP BY 1,
                  2,
                  3,
                  4,
                  5) AS B ON A.RETAILER = B.RETAILER
      AND A.PRODUCT = B.PRODUCT
      AND A.CATEGORY = B.CATEGORY
      AND A.BRAND = B.BRAND
      AND A.DATE = B.DATE
      GROUP BY 1,
               2,
               3,
               4,
               5,
               8
   ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 May 2023 09:53:37 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2023-05-09T09:53:37Z</dc:date>
    <item>
      <title>Help Request - Dataset(s) that mimic two excel pivots with slicers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874572#M345552</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;
&lt;P&gt;I'm having a SAS programming metal block and could use some help.&lt;/P&gt;
&lt;P&gt;I am trying to create a dataset(s) that mimics an excel report that has the following structure:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Raw Data output with string variables like Retailer, Product, Brand, and Category and numeric values like forecast and actuals&lt;/LI&gt;
&lt;LI&gt;A Pivot (#1) table sourcing this raw data taking an ABS value of a difference of two measures (example: actuals - forecast), but it only includes Brand and Category (so it is taking the difference the summation to only that level)&lt;/LI&gt;
&lt;LI&gt;A second pivot (#2) table that contains the sums forecast, actuals, and other Numerics.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;But&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;the difference between this pivot table is that it contains all variables&lt;/LI&gt;
&lt;LI&gt;A Results tab that contains the output of these pivots via sumifs and contains slicers that are linked to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;both&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;pivot tables. So that when, for instance, a retailer is selected it takes to total sum of forecast from pivot table #2, but maybe it will take the ABS difference from pivot #1&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The issue I'm having with converting into SAS is when using those slicers. Due to pivot #1's live link to the raw data, when retailer is chosen it knows what amounts to sum up even though the variable/column doesn't exist in that pivot.&lt;/P&gt;
&lt;P&gt;So I am having trouble summing up at the brand and category level, but still being able to filter-down on other variables.&lt;/P&gt;
&lt;P&gt;What I've tried so far:&lt;/P&gt;
&lt;P&gt;PROC SQL; CREATE TABLE PIVOT AS SELECT A.RETAILER, A.PRODUCT, A.CATEGORY, A.BRAND, A.DATE, SUM(A.ActualValues) as Actuals, SUM(A.Forecast) as Forecast, B.ABS_VALUE FROM WORK.DATA as A LEFT JOIN (SELECT RETAILER, PRODUCT, CATEGORY, BRAND, DATE, ABS(SUM(ActualValues) - SUM(FORECAST)) AS B.ABS_VALUE FROM WORK.DATA GROUP BY 1,2,3,4,5 ) as B ON A.RETAILER = B.RETAILER AND A.PRODUCT = B.PRODUCT AND A.CATEGORY = B.CATEGORY AND A.BRAND = B.BRAND AND A.DATE = B.DATE GROUP BY 1,2,3,4,5,8; QUIT;&lt;/P&gt;
&lt;P&gt;^ This didn't work since we have brands with multiple categories, so the output was incorrect when selecting a brand filter with multiple categories. Worked fine for for all others though.&lt;/P&gt;
&lt;P&gt;I also tried to just make a mapping table where I could recreate the pivot tables in theory and then just map over pivot #1 so it would contain variables like RETAILER and PRODUCT. This didn't work because there's no one-to-one matching. A retailer may have many brands. and a brand may have many retailers.&lt;/P&gt;
&lt;P&gt;Any thoughts?&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 22:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874572#M345552</guid>
      <dc:creator>illmatic</dc:creator>
      <dc:date>2023-05-08T22:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help Request - Dataset(s) that mimic two excel pivots with slicers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874576#M345556</link>
      <description>&lt;P&gt;Sounds like you don't want PROC SQL, you want to use ODS EXCEL and PROC REPORT together.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for us to you need to provide example data as SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions and examples&lt;/A&gt;). A lot of people ignore this request and provide data in some other format. &lt;STRONG&gt;DO &lt;FONT color="#FF0000"&gt;NOT&lt;/FONT&gt; PROVIDE DATA IN SOME OTHER FORMAT&lt;/STRONG&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We would also need to see a mock-up of the desired output (screen captures are ok in this case).&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 22:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874576#M345556</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-08T22:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help Request - Dataset(s) that mimic two excel pivots with slicers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874630#M345585</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;when calculating the ABS_VALUE you can not call it &lt;EM&gt;"B.ABS_VALUE"&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ABS(SUM(ActualValues) - SUM(FORECAST)) AS B.ABS_VALUE&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ABS(SUM(ActualValues) - SUM(FORECAST)) AS ABS_VALUE&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE PIVOT AS
      SELECT A.RETAILER,
             A.PRODUCT,
             A.CATEGORY,
             A.BRAND,
             A.DATE,
             SUM(A.ActualValues) AS Actuals,
             SUM(A.Forecast) AS Forecast,
             B.ABS_VALUE
      FROM WORK.DATA AS A
      LEFT JOIN
        (SELECT RETAILER,
                PRODUCT,
                CATEGORY,
                BRAND, DATE, ABS(SUM(ActualValues) - SUM(FORECAST)) AS ABS_VALUE
         FROM WORK.DATA
         GROUP BY 1,
                  2,
                  3,
                  4,
                  5) AS B ON A.RETAILER = B.RETAILER
      AND A.PRODUCT = B.PRODUCT
      AND A.CATEGORY = B.CATEGORY
      AND A.BRAND = B.BRAND
      AND A.DATE = B.DATE
      GROUP BY 1,
               2,
               3,
               4,
               5,
               8
   ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2023 09:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-Request-Dataset-s-that-mimic-two-excel-pivots-with-slicers/m-p/874630#M345585</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-09T09:53:37Z</dc:date>
    </item>
  </channel>
</rss>

