<?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: GTL waterfall chart aligning count and percent y-axes in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479974#M16583</link>
    <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;your solution worked great...until I tried it on the data for which I am creating the plot. &amp;nbsp;These counts are 2 orders of magnitude greater than those in the cars dataset and I had the problem where the next major tick mark would show up and the height of the initial bar would not line up with the 100% tick. &amp;nbsp;This seems to happen if the initial bar height is more than about 70% of the way from the last major tick value. &amp;nbsp;I made a small modification to the first 3 steps of the program I posted so you (or anyone else) can see the effect of increasing the counts. (See the SAS code below.) &amp;nbsp;A multiplier value of 111 increases the counts from 428 to 47508 and a 50,000 tick value is put on the y-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But...I discovered the THRESHOLDMAX= option for LINEAROPTS=() and setting that to 0 suppresses the last major tick value so your post is ACCEPTED AS A SOLUTION! &amp;nbsp;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;***Increase values of counts with arbitrary multiplier for testing different ranges on graph;
%let multiplier=111;

***Open SASHELP dataset;
data cars;
	set sashelp.cars;
	retain w &amp;amp;multiplier;
run;

***count number of vehicles, store in macro var;
proc sql;
	select &amp;amp;multiplier*count(*) AS NCars INTO :IBV
	from cars;
quit;

***count cars by Vehicle type;
proc freq data=cars;
	tables type / out=vtype(keep=type count percent rename=(type=vehtype));
	weight w;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Jul 2018 17:30:09 GMT</pubDate>
    <dc:creator>cdorger</dc:creator>
    <dc:date>2018-07-20T17:30:09Z</dc:date>
    <item>
      <title>GTL waterfall chart aligning count and percent y-axes</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479671#M16553</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;I want to create a waterfall chart that shows how counts drop as you move through the category plotted on the x-axis. &amp;nbsp;But it would also be nice to see percentages on a second y-axis at the right. &amp;nbsp;I have been able to jury-rig this somewhat by overlaying 2 waterfallchart plots where the first one draws no bars and then&amp;nbsp;using offsetmax= option for the y2axis. &amp;nbsp;But getting the 100% tick to line up exactly with the total number of counts has been tricky and takes some trial and error. &amp;nbsp;Is there a way to do this in the manner of columndatarange=unionall option in the layout lattice statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;***Open SASHELP dataset;
data cars;
    set sashelp.cars;
run;

***count number of vehicles, store in macro var;
proc sql;
	select count(*) AS NCars INTO :IBV
	from cars;
quit;

***count cars by Vehicle type;
proc freq data=cars;
	tables type / out=vtype(keep=type count percent rename=(type=vehtype));
run;

***Sort from greatest to least ;
proc sort data=vtype;
	by descending count;
run;

***Create numeric plotting xvar and format data for formatting discrete x axis;
data vtype2(keep=x vehtype count percent)
	f1(keep=start label fmtname TYPE);
	set vtype end=lastline;
	retain fmtname 'discax' TYPE 'N';
	x=_N_;
	count=-count;
	percent=-percent;
	start=x;
	label=vehtype;
	if not lastline then do;
		output vtype2;
		output f1;
	end;
run;

***Look at data for plot;
proc print data=vtype2;
run;

***Create format for X-axis;
proc format cntlin=f1;
run;

***Figure out what max tick value on y1 axis should be;
%let ymax=450;
***Compute offsetmax for Percent axis (Y2axis);
data _NULL_;
	call symput('OSM',put(&amp;amp;ymax/&amp;amp;totcars - 1,best4.));
run;

%put *********&amp;amp;OSM*************;

***Create template for overlaying waterfall chart with numbers on left axis and percent on right;
proc template;
	define statgraph wfal1;
	nmvar MAXY "max y axis value" OSM "OffSet Max" IBV "Init Bar Value";
		begingraph;
		entrytitle 'Waterfall of Models by Vehicle Type';
			layout overlay / xaxisopts=(label="Restriction"
										discreteopts=(
										tickvaluefitpolicy=split
										tickvaluesplitchar="*"
											)
										)
							 yaxisopts=(label="Number of Vehicles"
										offsetmax=0
							 			linearopts=(
													viewmin=0 viewmax=MAXY
													)
										)
							y2axisopts=(label="Percent of Vehicles"
										griddisplay=on
										offsetmax=.05
										linearopts=(viewmin=0 viewmax=100)
										)
				; *end LAYOUT OVERLAY stmt;
				*Percent on right side;
				waterfallchart category=x response=percent / yaxis=y2
														  finalbartickvalue=""
														  initialbartickvalue=""
														  datatransparency=1
														  initialbarvalue=100
														  stat=sum
														  ;
				*numbers on left side;
				waterfallchart category=x response=count / yaxis=y
														  finalbartickvalue="All Other"
														  initialbartickvalue="All Vehicles"
														  initialbarvalue=IBV
														  barlabel=TRUE
														  fillattrs=(color=GRAYC9)
														  initialbarattrs=(color=GRAYC9)
														  finalbarattrs=(color=GRAYC9)
														  stat=sum
														  ;
			endlayout;
		endgraph;
	end; *define;
run;

%let MAXY=450;
*** *** *** *** *** *** *** *** *** Options for HTML output *** *** *** *** *** *** *** *** *** *** *** ;
options orientation=landscape topmargin=0.5in bottommargin=0.5in leftmargin=0.5in rightmargin=0.5in;
ods _all_ close;
ods noproctitle;
ods graphics on /
			border=off
			height=600px
			width=800px
			reset=index(1) /* causes SAS to overwrite output images */
			;

ods html body="waterFallTest.html"
		path="&amp;lt;path&amp;gt;/SAS_output/"(url=none)
		;

	proc sgrender data=vtype2 template=wfal1;
		format x discax.;
	run;

ods html close;
ods graphics off;
ods listing;
options orientation=portrait;



Quit;
********************************************** END PROGRAM ************************************************;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 19:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479671#M16553</guid>
      <dc:creator>cdorger</dc:creator>
      <dc:date>2018-07-19T19:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: GTL waterfall chart aligning count and percent y-axes</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479780#M16578</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; All you need to do is set the maximum of the y axis to be the total number of cars, the maximum of the y2 axis to 100, and to set the maximum offset of both to be the same (e.g. 0.05).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my mod of your code.&amp;nbsp; I update your MAXY to be your IBV macro variable and set your offsetmax to both be 0.05.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
ods path WORK.TEMPLAT(UPDATE) SASHELP.TMPLMST (READ);
***Create template for overlaying waterfall chart with numbers on left axis and percent on right;
proc template;
    define statgraph wfal1;
    nmvar MAXY "max y axis value" OSM "OffSet Max" IBV "Init Bar Value";
        begingraph;
        entrytitle 'Waterfall of Models by Vehicle Type';
            layout overlay / xaxisopts=(label="Restriction"
                                        discreteopts=(
                                        tickvaluefitpolicy=split
                                        tickvaluesplitchar="*"
                                            )
                                        )
                             yaxisopts=(label="Number of Vehicles"
                                        offsetmax=0.05
                                        linearopts=(
                                                    viewmin=0 viewmax=MAXY
                                                    )
                                        )
                            y2axisopts=(label="Percent of Vehicles"
                                        offsetmax=0.05
                                        griddisplay=on
                                        linearopts=(viewmin=0 viewmax=100)
                                        )
                ; *end LAYOUT OVERLAY stmt;
                *Percent on right side;
                waterfallchart category=x response=percent / yaxis=y2
                                                          finalbartickvalue=""
                                                          initialbartickvalue=""
                                                          datatransparency=1
                                                          initialbarvalue=100
                                                          stat=sum
                                                          ;
                *numbers on left side;
                waterfallchart category=x response=count / yaxis=y
                                                          finalbartickvalue="All Other"
                                                          initialbartickvalue="All Vehicles"
                                                          initialbarvalue=IBV
                                                          barlabel=TRUE
                                                          fillattrs=(color=GRAYC9)
                                                          initialbarattrs=(color=GRAYC9)
                                                          finalbarattrs=(color=GRAYC9)
                                                          stat=sum
                                                          ;
            endlayout;
        endgraph;
    end; *define;
run;

%let MAXY=&amp;amp;ibv;
ods graphics on /
            border=off
            height=600px
            width=800px
            reset=index(1) /* causes SAS to overwrite output images */
            ;

    proc sgrender data=vtype2 template=wfal1;
        format x discax.;
    run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGRender1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21880iA1207DBFB7E9ED77/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGRender1.png" alt="SGRender1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 03:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479780#M16578</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2018-07-20T03:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: GTL waterfall chart aligning count and percent y-axes</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479974#M16583</link>
      <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;your solution worked great...until I tried it on the data for which I am creating the plot. &amp;nbsp;These counts are 2 orders of magnitude greater than those in the cars dataset and I had the problem where the next major tick mark would show up and the height of the initial bar would not line up with the 100% tick. &amp;nbsp;This seems to happen if the initial bar height is more than about 70% of the way from the last major tick value. &amp;nbsp;I made a small modification to the first 3 steps of the program I posted so you (or anyone else) can see the effect of increasing the counts. (See the SAS code below.) &amp;nbsp;A multiplier value of 111 increases the counts from 428 to 47508 and a 50,000 tick value is put on the y-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But...I discovered the THRESHOLDMAX= option for LINEAROPTS=() and setting that to 0 suppresses the last major tick value so your post is ACCEPTED AS A SOLUTION! &amp;nbsp;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;***Increase values of counts with arbitrary multiplier for testing different ranges on graph;
%let multiplier=111;

***Open SASHELP dataset;
data cars;
	set sashelp.cars;
	retain w &amp;amp;multiplier;
run;

***count number of vehicles, store in macro var;
proc sql;
	select &amp;amp;multiplier*count(*) AS NCars INTO :IBV
	from cars;
quit;

***count cars by Vehicle type;
proc freq data=cars;
	tables type / out=vtype(keep=type count percent rename=(type=vehtype));
	weight w;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jul 2018 17:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/GTL-waterfall-chart-aligning-count-and-percent-y-axes/m-p/479974#M16583</guid>
      <dc:creator>cdorger</dc:creator>
      <dc:date>2018-07-20T17:30:09Z</dc:date>
    </item>
  </channel>
</rss>

