<?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: Using BY to Draw Many HISTOGRAMs in PROC UNIVARIATE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554675#M154335</link>
    <description>&lt;P&gt;Proc UNIVARIATE uses ODS Graphics&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can achieve this as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do i=1 to 5;
    do t=1 to 5;
      x=rannor(1);
      output;
    end;
  end;
run;

ods _all_ close;

ods listing gpath="c:\temp";
ods graphics on;
ods graphics / reset=index imagefmt=png imagename="hist_#byval(i)";
title "Histogram for #byline";

proc univariate data=have noprint;
  var x;
  by i;
  histogram/normal(noprint) odstitle=title;
/*  format i z3.;*/
run;

title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some notes on the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Using the ODS LISTING destination you can specify the GPATH option to say where the graphics files are written too.&lt;/LI&gt;
&lt;LI&gt;Since SAS9.4M5 you can make use of the #BY... substitutions in the IMAGENAME option of ODS GRAHICS like you could in the TITLE statement, but now for the image name, otherwise is just numbers them.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;To have the TITLE text in your graphics file you use the ODSTITLE=TITLE option on the HISTOGRAM statement&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Mon, 29 Apr 2019 12:19:09 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2019-04-29T12:19:09Z</dc:date>
    <item>
      <title>Using BY to Draw Many HISTOGRAMs in PROC UNIVARIATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554647#M154323</link>
      <description>&lt;P&gt;How can I output multiple HISTOGRAM image files with BY in PROC UNIVARIATE? Suppose I have the following panel data set.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _;
do i=1 to 5;
do t=1 to 5;
x=rannor(1);
output;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_.png" style="width: 288px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29092i52A86F1887E61D19/image-size/large?v=v2&amp;amp;px=999" role="button" title="_.png" alt="_.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried the following code, but it just overwrote the destination file five times.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename _ "!userprofile\desktop\_.png";
goption gsfname=_ device=png gsfmode=replace;
ods results=off;
proc univariate noprint;
var x;
by i;
histogram/normal(noprint);
run;
ods results=on;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is the log.&lt;/P&gt;&lt;PRE&gt;11   filename _ "!userprofile\desktop\_.png";
12   goption gsfname=_ device=png gsfmode=replace;
13   ods results=off;
14   proc univariate noprint;
15   var x;
16   by i;
17   histogram/normal(noprint);
18   run;

NOTE: 11265 bytes written to C:\Users\Junyong\desktop\_.png.
NOTE: The above message was for the following BY group:
      i=1
NOTE: 11665 bytes written to C:\Users\Junyong\desktop\_.png.
NOTE: The above message was for the following BY group:
      i=2
NOTE: 10306 bytes written to C:\Users\Junyong\desktop\_.png.
NOTE: The above message was for the following BY group:
      i=3
NOTE: 11258 bytes written to C:\Users\Junyong\desktop\_.png.
NOTE: The above message was for the following BY group:
      i=4
NOTE: 10640 bytes written to C:\Users\Junyong\desktop\_.png.
NOTE: The above message was for the following BY group:
      i=5
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.65 seconds
      cpu time            0.65 seconds


19   ods results=on;&lt;/PRE&gt;&lt;P&gt;Is there any way to collect the five HISTOGRAMs separately?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 06:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554647#M154323</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-04-29T06:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using BY to Draw Many HISTOGRAMs in PROC UNIVARIATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554651#M154325</link>
      <description>&lt;P&gt;If you need an image per seperate histogram my suggestion would be using a macro like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro multiple_outputs(i);
	filename _&amp;amp;i. "!userprofile\desktop\_&amp;amp;i..png";
	goption gsfname=_ device=png gsfmode=replace;
	ods results=off;

	data work.temp;
		set _;
		where i = &amp;amp;i.;
	run;

	proc Univariate noprint;
		var x;
		by i;
		histogram/normal(noprint);
	run;

	ods results=on;
%mend multiple_outputs;

data _null_;
	set _;
	by i;

	if first.i then
		do;
			arg1 = '%nrstr(%multiple_outputs('!!i!!'));';
			call execute(arg1);
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I believe somebody will have a solution without having to fall back on macro code which would be a better solution, but I don't know one. I hope this helps you anyways.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards&lt;/P&gt;
&lt;P&gt;Criptic&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 07:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554651#M154325</guid>
      <dc:creator>Criptic</dc:creator>
      <dc:date>2019-04-29T07:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using BY to Draw Many HISTOGRAMs in PROC UNIVARIATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554675#M154335</link>
      <description>&lt;P&gt;Proc UNIVARIATE uses ODS Graphics&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can achieve this as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do i=1 to 5;
    do t=1 to 5;
      x=rannor(1);
      output;
    end;
  end;
run;

ods _all_ close;

ods listing gpath="c:\temp";
ods graphics on;
ods graphics / reset=index imagefmt=png imagename="hist_#byval(i)";
title "Histogram for #byline";

proc univariate data=have noprint;
  var x;
  by i;
  histogram/normal(noprint) odstitle=title;
/*  format i z3.;*/
run;

title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some notes on the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Using the ODS LISTING destination you can specify the GPATH option to say where the graphics files are written too.&lt;/LI&gt;
&lt;LI&gt;Since SAS9.4M5 you can make use of the #BY... substitutions in the IMAGENAME option of ODS GRAHICS like you could in the TITLE statement, but now for the image name, otherwise is just numbers them.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;To have the TITLE text in your graphics file you use the ODSTITLE=TITLE option on the HISTOGRAM statement&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 29 Apr 2019 12:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-BY-to-Draw-Many-HISTOGRAMs-in-PROC-UNIVARIATE/m-p/554675#M154335</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2019-04-29T12:19:09Z</dc:date>
    </item>
  </channel>
</rss>

