<?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: Historgram R equivalent y axis in SAS in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941441#M24972</link>
    <description>&lt;P&gt;Caveat: I don't speak R, so I have no real understanding of that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to assume that you have a SAS data set. So I would suggest first running Proc SGPLOT with all the defaults for a histogram:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable;
run;&lt;/PRE&gt;
&lt;P&gt;And see how well that works for what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I see something like "y = 100*after_stat" in code I suspect that Percentages may be involved and this converting decimal .3 to 30 percent. If that is the case then perhaps the option SCALE=PERCENT would be appropriate for the code:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable  /   scale=percent;
run;&lt;/PRE&gt;
&lt;P&gt;SAS has two basic options for setting the widths NBINS= or BIDWIDTH=. The first sets the number of bins, other sets a width based on the values of the variable to group together. If you want 100 bins&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable  /   scale=percent
                        nbins=100
;
run;&lt;/PRE&gt;
&lt;P&gt;If you want each bin to span 2.5 units&amp;nbsp; (of what ever is measured)&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable  /   scale=percent
                        binwidth=2.5
;
run;&lt;/PRE&gt;
&lt;P&gt;Look in the online help for other options and experiment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need help with options then be prepared to provide example data as a working data step and example code that got "close" to what you want. Then describe what is needed to modify the plot.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2024 14:26:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-08-28T14:26:52Z</dc:date>
    <item>
      <title>Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941304#M24970</link>
      <description>&lt;P&gt;I wanted to create an R equivalent SAS code for the below one. I am not an expert in R. I tried to understand especially y-axis calculation in SAS. How do we drive it or any function in SAS to get this value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;mpg %&amp;gt;% ggplot(aes(displ,fill = factor(cyl), color = factor(cyl))) +
geom_histogram(aes(y = 100*after_stat(width*density)),
binwidth = 2.5,
position = position_dodge())&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2024 08:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941304#M24970</guid>
      <dc:creator>Rajaram</dc:creator>
      <dc:date>2024-08-28T08:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941414#M24971</link>
      <description>&lt;P&gt;Can you run this and post a picture?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 13:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941414#M24971</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2024-08-28T13:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941441#M24972</link>
      <description>&lt;P&gt;Caveat: I don't speak R, so I have no real understanding of that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to assume that you have a SAS data set. So I would suggest first running Proc SGPLOT with all the defaults for a histogram:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable;
run;&lt;/PRE&gt;
&lt;P&gt;And see how well that works for what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I see something like "y = 100*after_stat" in code I suspect that Percentages may be involved and this converting decimal .3 to 30 percent. If that is the case then perhaps the option SCALE=PERCENT would be appropriate for the code:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable  /   scale=percent;
run;&lt;/PRE&gt;
&lt;P&gt;SAS has two basic options for setting the widths NBINS= or BIDWIDTH=. The first sets the number of bins, other sets a width based on the values of the variable to group together. If you want 100 bins&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable  /   scale=percent
                        nbins=100
;
run;&lt;/PRE&gt;
&lt;P&gt;If you want each bin to span 2.5 units&amp;nbsp; (of what ever is measured)&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=yourdatasetname;
histogram variable  /   scale=percent
                        binwidth=2.5
;
run;&lt;/PRE&gt;
&lt;P&gt;Look in the online help for other options and experiment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need help with options then be prepared to provide example data as a working data step and example code that got "close" to what you want. Then describe what is needed to modify the plot.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 14:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941441#M24972</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-28T14:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941676#M24978</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rajaram_0-1724928059658.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99733i4233858BF459F8AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rajaram_0-1724928059658.png" alt="Rajaram_0-1724928059658.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Attached is the output from R. I have also attached data from R, my manual calculation, and the Excel output.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 10:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941676#M24978</guid>
      <dc:creator>Rajaram</dc:creator>
      <dc:date>2024-08-29T10:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941682#M24979</link>
      <description>&lt;P&gt;Most of us will not download Excel files, as they are a security threat. We need to have data provided as working 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;examples and instructions&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, what is the Y axis? Is it really "percent"? Or is it something else?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 11:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941682#M24979</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-29T11:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941690#M24980</link>
      <description>&lt;P&gt;I have attached SAS dataset and R output in one of the replies.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 11:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941690#M24980</guid>
      <dc:creator>Rajaram</dc:creator>
      <dc:date>2024-08-29T11:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941691#M24981</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am unable to download your SAS data set because of firewall restrictions here at work. So, repeating:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;We need to have data provided as working SAS data step code (&lt;/SPAN&gt;&lt;A style="background: #ffffff; color: #0168b2; transition: all 0.3s ease 0s; font-size: 14px;" href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self" rel="nofollow noopener noreferrer"&gt;examples and instructions&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please answer my question about the Y-axis.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 11:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941691#M24981</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-29T11:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941728#M24982</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34124"&gt;@Rajaram&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have attached SAS dataset and R output in one of the replies.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your data set has two variables, dspl and trt. Dspl has 35 different values. So I think something has been skipped in providing how you reduce 35 levels to apparently 3 for the plot (and to tell the truth that x axis on the plot looks pretty odd given the way the values are displayed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are grouping Dspl by ranges of values that is typically done with a format in SAS.&lt;/P&gt;
&lt;P&gt;Your description didn't include how to calculate what appears to be a percentage so I take what I think you wanted and use Proc Freq as one of the basic tools for counting and percentage calculations.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value dspl
low - 3 = '[1.6, 3]'
3 &amp;lt;-  5 = '(3, 5]'
5 &amp;lt;-high= '&amp;gt;5'
;
run;
proc freq data= tmp1.tmpg noprint;
   tables trt*dspl/outpct out=work.summary;
   format dspl dspl. ;
run;


proc sgplot data=work.summary;
   vbar dspl  / group=trt  groupdisplay=cluster
                response=pct_row
   ;
   label dspl='Displacement'
         trt='Treatment'
         pct_row='Percent of Treatment'
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;Hopefully the ranges of the Dspl format in the Proc Format are easy enough to adjust to your need as your plot from R leaves a greate deal of missing details as to what was done. I display the ranges to delineate the actual ranges of the values. For those who don't remember their math courses the [ or ] indicates the value is included in the range, ( or ) the value is not included in the range but is as close as you want (3, 5] means &amp;gt;3 and less than or equal to 5 for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the use of LABEL statement to place meaningful text in the Axis and legend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless everyone seeing this graph will immediately understand what value(s) TRT1 indicates I would also create a format to display meaningful text instead of trt1, trt2 etc. in the legend.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 14:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941728#M24982</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-29T14:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Historgram R equivalent y axis in SAS</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941918#M24983</link>
      <description>&lt;P&gt;Thank you. I changed format it matched my excel output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
value dspl
low - 3.25 = '2.5'
3.25 &amp;lt;-  6.25 = '5'
6.25 &amp;lt;-high= '7.5'
;
run;

proc freq data= data.tmpg noprint;
   tables trt*dspl/outpct out=work.summary;
   format dspl dspl. ;
run;


proc sgplot data=work.summary;
   vbar dspl  / group=trt  groupdisplay=cluster
                response=pct_row
   ;
   label dspl='Displacement'
         trt='Treatment'
         pct_row='Percent of Treatment'
   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Aug 2024 08:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Historgram-R-equivalent-y-axis-in-SAS/m-p/941918#M24983</guid>
      <dc:creator>Rajaram</dc:creator>
      <dc:date>2024-08-30T08:31:03Z</dc:date>
    </item>
  </channel>
</rss>

