<?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: Create dataset for waterfall chart? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344896#M79313</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=',';
input name :$20. count type $;
datalines;
Total Base,1000000,Base
first filter,900000,Filter
second filter,500000,Filter
third filter,400000,Filter
;
run;

data want;
set have (rename=(count=oldcount));
retain keepcount;
if type = 'Base'
then do;
  keepcount = oldcount;
  count = oldcount;
end;
if type = 'Filter'
then do;
  count = oldcount - keepcount;
  keepcount = keepcount + count;
end;
drop keepcount oldcount;
run;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this produces a different value for the third filter:&lt;/P&gt;
&lt;PRE&gt;    name          type       count

Total Base       Base       1000000
first filter     Filter     -100000
second filter    Filter     -400000
third filter     Filter     -100000
&lt;/PRE&gt;
&lt;P&gt;Did I miss something, or was that a miscalculation in your example?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2017 07:00:16 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-03-28T07:00:16Z</dc:date>
    <item>
      <title>Create dataset for waterfall chart?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344890#M79310</link>
      <description>&lt;P&gt;I often come across tasks where I need to present the drop off total counts as certain criteria are applied to the original base population.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the table is then presented in this manner&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input name $ count type $;
datalines;
Total Base 1000000 Base
first filter 900000 Filter
second filter 500000 Filter
third filter 400000 Filter;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The table shows the total number after each filter has been applied consecutively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the waterfall chart&amp;nbsp;&lt;A href="http://blogs.sas.com/content/iml/2015/04/27/cascade-chart.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2015/04/27/cascade-chart.html&lt;/A&gt; requires a slightly different&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datalines;
Total Base 1000000 Base
first filter -100000 Filter
second filter -400000 Filter
third filter -200000 Filter;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that the number of filter may varies from time to time. How can I generate the second table before applying the proc sgplot?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 06:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344890#M79310</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-28T06:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset for waterfall chart?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344896#M79313</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=',';
input name :$20. count type $;
datalines;
Total Base,1000000,Base
first filter,900000,Filter
second filter,500000,Filter
third filter,400000,Filter
;
run;

data want;
set have (rename=(count=oldcount));
retain keepcount;
if type = 'Base'
then do;
  keepcount = oldcount;
  count = oldcount;
end;
if type = 'Filter'
then do;
  count = oldcount - keepcount;
  keepcount = keepcount + count;
end;
drop keepcount oldcount;
run;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this produces a different value for the third filter:&lt;/P&gt;
&lt;PRE&gt;    name          type       count

Total Base       Base       1000000
first filter     Filter     -100000
second filter    Filter     -400000
third filter     Filter     -100000
&lt;/PRE&gt;
&lt;P&gt;Did I miss something, or was that a miscalculation in your example?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 07:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344896#M79313</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-28T07:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset for waterfall chart?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344899#M79314</link>
      <description>&lt;P&gt;Terrific! Yes, you are right, the last value was a miscalculation. Apologize. Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 12:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/344899#M79314</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-28T12:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset for waterfall chart?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/345017#M79333</link>
      <description>&lt;P&gt;And for lazy programmers:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   dif=dif(count);
   if type ne 'Base' then count=dif;
   drop dif;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2017 15:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-for-waterfall-chart/m-p/345017#M79333</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-28T15:14:38Z</dc:date>
    </item>
  </channel>
</rss>

