<?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: sgplot color a specific proportion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809039#M319026</link>
    <description>&lt;P&gt;Yes, sounds like you have a problem. My example handles negative X values without any problem, so be sure to study it carefully. The logic for setting up the points for the BAND statement depends only on the cumulative proportions, not on X.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2022 12:41:13 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2022-04-21T12:41:13Z</dc:date>
    <item>
      <title>sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/808988#M319004</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made a plot looking like the below and i want to highlight were the middle 95% is (meaning approximately from -4 to +4 on the x axis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is that a feature in proc sgplot ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lone0708_1-1650534887109.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70660iC8F0860869FC6724/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lone0708_1-1650534887109.png" alt="lone0708_1-1650534887109.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 09:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/808988#M319004</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2022-04-21T09:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809000#M319007</link>
      <description>&lt;P&gt;Yes: Use the BAND statement.&amp;nbsp; For an example and discussion, see &lt;A href="https://blogs.sas.com/content/iml/2015/07/20/density-shaded-tails.html" target="_self"&gt;"Create a density curve with shaded tails."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That article shades the tails, whereas you want to shade the interior. For your problem, the solution will look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input x y;
datalines;
-14 0.5
-12 0.6
-10 0.6
-8 0.8
-6 1.2
-4 2.2
-2 4.5
0  17
2  5.4
4  1.9
6  1.4
8  2.1
10 1.4
12 1.3
14 1.4
; 

data Want;
set Have;
low  = -4;   /* lower value to shade */
high = 4;    /* upper value to shade */
if x&amp;gt;=low  and x &amp;lt;=high then 
   upper = y; 
else 
   upper = .;
drop low high;
run;

proc sgplot data=Want;
   band x=x upper=upper lower=0;
   series x=x y=y/ datalabel markers;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2022 10:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809000#M319007</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-04-21T10:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809005#M319010</link>
      <description>Fantastic! Thanks &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;If I want to exchange the -4, +4 with a specific proportion e.g. meaning the 95% of the proportion are within the band. How do I write that in the low/high statement?&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Apr 2022 10:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809005#M319010</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2022-04-21T10:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809009#M319013</link>
      <description>&lt;P&gt;As discussed in the article, one way is to rescale the curve so that it becomes a density. If your data are equally spaced in X, you can get away with just rescaling the Y heights by dividing by the sum of heights. The following statements compute the (scaled) cumulative distribution and then shade the region that excludes the lower and upper alpha/2 proportion of the heights. That means it keeps the interior 1-alpha proportion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* compute sum and put it into macro variable */
proc sql;
select sum(y) into :sum
 from Have;
quit;
%put &amp;amp;=sum;

/* create the cumulative density variable */
data Cumul;
set Have;
cumul + y / &amp;amp;sum;
run;

/* shade where the cumulitive density is greater than alpha/2
   and less than 1-alpha/2 */
data Want;
alpha = 0.05;  /* ask for 95% region */
set Cumul;
if cumul&amp;gt;=alpha/2  and cumul &amp;lt;=1-alpha/2 then 
   upper = y; 
else 
   upper = .;
run;
/* graph it */
proc sgplot data=Want;
   band x=x upper=upper lower=0;
   series x=x y=y/ datalabel markers;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809009#M319013</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-04-21T11:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809013#M319016</link>
      <description>It seems to work beautifully!&lt;BR /&gt;but, I think I have a problem because my x values can be negative. Right now, the band stops at zero (and does not take the negative values into account).&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809013#M319016</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2022-04-21T11:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809039#M319026</link>
      <description>&lt;P&gt;Yes, sounds like you have a problem. My example handles negative X values without any problem, so be sure to study it carefully. The logic for setting up the points for the BAND statement depends only on the cumulative proportions, not on X.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 12:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/809039#M319026</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-04-21T12:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810259#M319517</link>
      <description>&lt;P&gt;Hi Rick,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hmm i cannot understand, why this code gives me a plot looking like this as its the proportion around 0 i need to be shaded. Maybe you can help me out ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70922i27C55CD3F746DEBA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Skærmbillede 2022-04-27 kl. 20.52.06.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70920iC938A54BA93B24AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Skærmbillede 2022-04-27 kl. 20.52.06.png" alt="Skærmbillede 2022-04-27 kl. 20.52.06.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 18:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810259#M319517</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2022-04-27T18:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810260#M319518</link>
      <description>&lt;P&gt;Try alpha=0.05 instead of alpha=0.5.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 18:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810260#M319518</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-04-27T18:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810261#M319519</link>
      <description>Hmm, it is still the same.&lt;BR /&gt;</description>
      <pubDate>Wed, 27 Apr 2022 19:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810261#M319519</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2022-04-27T19:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810266#M319522</link>
      <description>&lt;P&gt;I don't know. However, I suggest that you avoid overwriting the ABC data set. If you run this code a second time, it will overwrite the ABC data, which will surely corrupt the results. Don't use&amp;nbsp;&lt;BR /&gt;data ABC;&lt;/P&gt;
&lt;P&gt;set CUMUL;&lt;/P&gt;
&lt;P&gt;when CUMUL was generated from ABC.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 19:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810266#M319522</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-04-27T19:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: sgplot color a specific proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810269#M319525</link>
      <description>And that fixed the problem…… THANKS ! &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 27 Apr 2022 19:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sgplot-color-a-specific-proportion/m-p/810269#M319525</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2022-04-27T19:19:24Z</dc:date>
    </item>
  </channel>
</rss>

