<?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: A simple histogram - how hard can it be? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334934#M11650</link>
    <description>&lt;P&gt;Thank you! Don't think I would have found that sollution on my own.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simple way to split this chart by say gender? So that I get a stacked histogram?&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2017 13:14:59 GMT</pubDate>
    <dc:creator>Ullsokk</dc:creator>
    <dc:date>2017-02-22T13:14:59Z</dc:date>
    <item>
      <title>A simple histogram - how hard can it be?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334916#M11647</link>
      <description>&lt;P&gt;I have been tearing my hair out with frustration for the last hour. I just want a histogram for my age distribution, in bins of 1 bar per age category (age in years, no decimals in the data), showing values 0, 5, 10 etc in the x-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working from Enterprise Guide.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot believe how many different procs there are to make histograms, each with different syntax. There is the&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc univairate data=mydate;
histogram age; 
run;&lt;/PRE&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc gchart data=mydata;
vbar age /discrete;
run;&lt;/PRE&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SGPLOT DATA = mydata;
 HISTOGRAM age/binwidth=1 binstart=0;
 TITLE "Age";
 xaxis values=(0 to 100 by 1);
RUN; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The closest I have come is with the SGPLOT, but the first bar is halvway hidden behind the Y axis. Does anyone know how to make the first bar visible?&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7392i82C8D3F99093410E/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="age.PNG" title="age.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, which command would you use to generate a simple histogram like this? Is there something like a best practice? Are some of these older procs getting faded out?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 12:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334916#M11647</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2017-02-22T12:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: A simple histogram - how hard can it be?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334929#M11649</link>
      <description>&lt;P&gt;You're correct that there are many ways to create a histogram -- you touched only on a few of them! &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the simplest method is the one you tried last: PROC SGPLOT. &amp;nbsp;Since you have 100 bins and the graph is only so wide, the algorithm to make everything fit might make your left-most extreme value seem very tight against the axis. &amp;nbsp;You can use the OFFSETMIN= option to give a little more space. &amp;nbsp;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample (keep=age);
 do i = 1 to 100000;
   age = abs ( floor ( rand('triangle',0.1) * 100 ) );
   output;
 end;
run;

ods graphics / width=1000px height=400px;
proc sgplot data=sample;
 HISTOGRAM age / binwidth=1 binstart=0 ;
 TITLE "Age";
 xaxis values=(0 to 100 by 1) offsetmin=.01 offsetmax=.01 ;
RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7395iEBE94082583B4630/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="hist.png" title="hist.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 12:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334929#M11649</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-02-22T12:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: A simple histogram - how hard can it be?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334934#M11650</link>
      <description>&lt;P&gt;Thank you! Don't think I would have found that sollution on my own.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simple way to split this chart by say gender? So that I get a stacked histogram?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 13:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334934#M11650</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2017-02-22T13:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: A simple histogram - how hard can it be?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334959#M11652</link>
      <description>&lt;P&gt;Of course! Again, multple methods, but now it sounds like you're more interested in a VBAR with a grouping variable than a classic histogram of statistical distribution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try PROC SGPANEL with a HISTOGRAM statement and PANELBY for gender (that would yield two histograms). &amp;nbsp;Or you could use PROC FREQ to calc the percentages into a data set, then use a step like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=freq_output;
 vbar age / response=percent group=gender grouporder=data;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 14:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334959#M11652</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-02-22T14:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: A simple histogram - how hard can it be?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334974#M11653</link>
      <description>&lt;P&gt;Building on Chris' example, here are three variations you do with your grouping variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value gender 1="Male"
             2="Female"
;
run;

data sample (keep=age g);
 do g = 1 to 2;
 do i = 1 to 100000;
   age = abs ( floor ( rand('triangle',0.1) * 100 ) );
   output;
 end;
 end;
run;

ods graphics / width=1000px height=400px;
proc sgplot data=sample;
format g gender.;
 by g;
 HISTOGRAM age / binwidth=1 binstart=0 ;
 TITLE "Age";
 xaxis values=(0 to 100 by 1) offsetmin=.01 offsetmax=.01 ;
RUN;

proc sgplot data=sample;
format g gender.;
 HISTOGRAM age / binwidth=1 binstart=0 group=g transparency=0.5;
 TITLE "Age";
 xaxis values=(0 to 100 by 1) offsetmin=.01 offsetmax=.01 ;
RUN;

proc sgpanel data=sample;
format g gender.;
 panelby g / layout=rowlattice novarname;
 HISTOGRAM age / binwidth=1 binstart=0 ;
 TITLE "Age";
 colaxis values=(0 to 100 by 1) offsetmin=.01 offsetmax=.01 ;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2017 14:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/A-simple-histogram-how-hard-can-it-be/m-p/334974#M11653</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2017-02-22T14:57:29Z</dc:date>
    </item>
  </channel>
</rss>

