<?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 Using sgplot to create 4 separate graphs for multiple facilities in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/677898#M20384</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;My data set includes six months' of data for several different healthcare facilities.&amp;nbsp; I don't need to do any calculations, they've already been performed.&amp;nbsp; I'm using sgplot to create a bar line graph with my bars being individual facility data and the line being the total average data for all facilities.&amp;nbsp; I'm creating a total of 4 graphs for each facility, one for each of the measures I'm looking at.&amp;nbsp; How can I get the data to go through the sgplot so that each facility has all 4 graphs on a page together.&amp;nbsp; I'm able to get 4 graphs on a page, but they're for 4 different facilities, the same data graph, i.e., one page with have 4 graphs for Length of Stay for 4 different facilities, rather than a graph of the 4 different measures for all the same facility.&amp;nbsp; I imagine I need to use a macro, but I'm stuck, as macros are a weakness for me.&amp;nbsp; I'm using SAS 9.4.&amp;nbsp; I've attached a dummy data set and this is the code I'm using:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;options nodate nonumber orientation=landscape;&lt;/P&gt;&lt;P&gt;goptions reset=all device=sasprtc htitle=13pt ftext="Helvetica/bold";&lt;/P&gt;&lt;P&gt;ods _all_ close;&lt;BR /&gt;ods pdf file='data.pdf' notoc dpi=300 startpage=no;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Paid per Day";&lt;BR /&gt;vbar Date /response = Average_Paid_Per_Day;&lt;BR /&gt;vline date/response = Total_Avg_Paid_Per_Day y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Paid per Discharge";&lt;BR /&gt;vbar Date / response = Average_Paid_Per_Discharge;&lt;BR /&gt;vline date / response = Total_Avg_Paid_Per_Discharge y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Length of Stay";&lt;BR /&gt;vbar Date / response = Average_Length_of_Stay;&lt;BR /&gt;vline Date / response = Total_Avg_LOS y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Readmission Rates";&lt;BR /&gt;vbar Date / response = Readmission_Rate;&lt;BR /&gt;vline Date / response = Total_Readmission_Rates y2axis;&lt;BR /&gt;by CCN_Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ods _all_ close;&lt;BR /&gt;ods listing;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Aug 2020 20:16:22 GMT</pubDate>
    <dc:creator>sasroper</dc:creator>
    <dc:date>2020-08-19T20:16:22Z</dc:date>
    <item>
      <title>Using sgplot to create 4 separate graphs for multiple facilities</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/677898#M20384</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;My data set includes six months' of data for several different healthcare facilities.&amp;nbsp; I don't need to do any calculations, they've already been performed.&amp;nbsp; I'm using sgplot to create a bar line graph with my bars being individual facility data and the line being the total average data for all facilities.&amp;nbsp; I'm creating a total of 4 graphs for each facility, one for each of the measures I'm looking at.&amp;nbsp; How can I get the data to go through the sgplot so that each facility has all 4 graphs on a page together.&amp;nbsp; I'm able to get 4 graphs on a page, but they're for 4 different facilities, the same data graph, i.e., one page with have 4 graphs for Length of Stay for 4 different facilities, rather than a graph of the 4 different measures for all the same facility.&amp;nbsp; I imagine I need to use a macro, but I'm stuck, as macros are a weakness for me.&amp;nbsp; I'm using SAS 9.4.&amp;nbsp; I've attached a dummy data set and this is the code I'm using:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;options nodate nonumber orientation=landscape;&lt;/P&gt;&lt;P&gt;goptions reset=all device=sasprtc htitle=13pt ftext="Helvetica/bold";&lt;/P&gt;&lt;P&gt;ods _all_ close;&lt;BR /&gt;ods pdf file='data.pdf' notoc dpi=300 startpage=no;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Paid per Day";&lt;BR /&gt;vbar Date /response = Average_Paid_Per_Day;&lt;BR /&gt;vline date/response = Total_Avg_Paid_Per_Day y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Paid per Discharge";&lt;BR /&gt;vbar Date / response = Average_Paid_Per_Discharge;&lt;BR /&gt;vline date / response = Total_Avg_Paid_Per_Discharge y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Length of Stay";&lt;BR /&gt;vbar Date / response = Average_Length_of_Stay;&lt;BR /&gt;vline Date / response = Total_Avg_LOS y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Readmission Rates";&lt;BR /&gt;vbar Date / response = Readmission_Rate;&lt;BR /&gt;vline Date / response = Total_Readmission_Rates y2axis;&lt;BR /&gt;by CCN_Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ods _all_ close;&lt;BR /&gt;ods listing;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 20:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/677898#M20384</guid>
      <dc:creator>sasroper</dc:creator>
      <dc:date>2020-08-19T20:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using sgplot to create 4 separate graphs for multiple facilities</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/677905#M20385</link>
      <description>&lt;P&gt;1. Remove the BY statement&lt;/P&gt;
&lt;P&gt;2. Add a WHERE statement to filter for a single location.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Make sure the graph and file is generated as needed.&lt;/P&gt;
&lt;P&gt;4. Convert to a macro using the following &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_self"&gt;approach&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/342335"&gt;@sasroper&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;My data set includes six months' of data for several different healthcare facilities.&amp;nbsp; I don't need to do any calculations, they've already been performed.&amp;nbsp; I'm using sgplot to create a bar line graph with my bars being individual facility data and the line being the total average data for all facilities.&amp;nbsp; I'm creating a total of 4 graphs for each facility, one for each of the measures I'm looking at.&amp;nbsp; How can I get the data to go through the sgplot so that each facility has all 4 graphs on a page together.&amp;nbsp; I'm able to get 4 graphs on a page, but they're for 4 different facilities, the same data graph, i.e., one page with have 4 graphs for Length of Stay for 4 different facilities, rather than a graph of the 4 different measures for all the same facility.&amp;nbsp; I imagine I need to use a macro, but I'm stuck, as macros are a weakness for me.&amp;nbsp; I'm using SAS 9.4.&amp;nbsp; I've attached a dummy data set and this is the code I'm using:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;options nodate nonumber orientation=landscape;&lt;/P&gt;
&lt;P&gt;goptions reset=all device=sasprtc htitle=13pt ftext="Helvetica/bold";&lt;/P&gt;
&lt;P&gt;ods _all_ close;&lt;BR /&gt;ods pdf file='data.pdf' notoc dpi=300 startpage=no;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Paid per Day";&lt;BR /&gt;vbar Date /response = Average_Paid_Per_Day;&lt;BR /&gt;vline date/response = Total_Avg_Paid_Per_Day y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Paid per Discharge";&lt;BR /&gt;vbar Date / response = Average_Paid_Per_Discharge;&lt;BR /&gt;vline date / response = Total_Avg_Paid_Per_Discharge y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Average Length of Stay";&lt;BR /&gt;vbar Date / response = Average_Length_of_Stay;&lt;BR /&gt;vline Date / response = Total_Avg_LOS y2axis;&lt;BR /&gt;by Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;ods graphics / reset=all height=1.7in width=8in;&lt;BR /&gt;proc sgplot data=snf_complete;&lt;BR /&gt;title "Readmission Rates";&lt;BR /&gt;vbar Date / response = Readmission_Rate;&lt;BR /&gt;vline Date / response = Total_Readmission_Rates y2axis;&lt;BR /&gt;by CCN_Facility_Name;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ods _all_ close;&lt;BR /&gt;ods listing;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 21:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/677905#M20385</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-19T21:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using sgplot to create 4 separate graphs for multiple facilities</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/678307#M20386</link>
      <description>&lt;P&gt;The attached code will create a page for each facility by looping over a list of the names extracted by proc sql.&amp;nbsp; I would even go further and create a single sgplot inside a macro that would create all 4 graphs&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro graphit;
ods graphics / reset=all height=1.7in width=8in;
proc sgplot data=snf_complete;
title "Average Paid per Day";
vbar Date /response = Average_Paid_Per_Day;
vline date/response = Total_Avg_Paid_Per_Day y2axis;
by Facility_Name;
run;

ods graphics / reset=all height=1.7in width=8in;
proc sgplot data=snf_complete;
title "Average Paid per Discharge";
vbar Date / response = Average_Paid_Per_Discharge;
vline date / response = Total_Avg_Paid_Per_Discharge y2axis;
by Facility_Name;
run;

ods graphics / reset=all height=1.7in width=8in;
proc sgplot data=snf_complete;
title "Average Length of Stay";
vbar Date / response = Length_of_Stay;
vline Date / response = Total_Avg_LOS y2axis;
by Facility_Name;
run;

ods graphics / reset=all height=1.7in width=8in;
proc sgplot data=snf_complete;
title "Readmission Rates";
vbar Date / response = Readmission_Rate;
vline Date / response = Total_Readmission_Rates y2axis;
by Facility_Name;
run;
%mend;

/* Make a list of facilities */
proc sql;
   create table facility as 
   		select distinct Facility_Name 
   			from all;
quit;

options nodate nonumber orientation=landscape;

goptions reset=all device=sasprtc htitle=13pt ftext="Helvetica/bold";

ods _all_ close;
ods pdf file='~/dat/data.pdf' notoc dpi=300 startpage=no;
/* Loop over the list */
data _null_;
  set facility;
  call symput('fn',trim(Facility_Name));
  call execute(
  	'data snf_complete;
  		set all; 
  			where Facility_Name="&amp;amp;fn";
  		%graphit;
  		');
run;
ods _all_ close;
ods listing;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Aug 2020 03:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/678307#M20386</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-08-21T03:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using sgplot to create 4 separate graphs for multiple facilities</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/678580#M20402</link>
      <description>Thank you!! Both solutions worked for me. I really appreciate the help!</description>
      <pubDate>Fri, 21 Aug 2020 20:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-sgplot-to-create-4-separate-graphs-for-multiple-facilities/m-p/678580#M20402</guid>
      <dc:creator>sasroper</dc:creator>
      <dc:date>2020-08-21T20:27:49Z</dc:date>
    </item>
  </channel>
</rss>

