BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasroper
Calcite | Level 5

Hello,

My data set includes six months' of data for several different healthcare facilities.  I don't need to do any calculations, they've already been performed.  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.  I'm creating a total of 4 graphs for each facility, one for each of the measures I'm looking at.  How can I get the data to go through the sgplot so that each facility has all 4 graphs on a page together.  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.  I imagine I need to use a macro, but I'm stuck, as macros are a weakness for me.  I'm using SAS 9.4.  I've attached a dummy data set and this is the code I'm using:


options nodate nonumber orientation=landscape;

goptions reset=all device=sasprtc htitle=13pt ftext="Helvetica/bold";

ods _all_ close;
ods pdf file='data.pdf' notoc dpi=300 startpage=no;


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 = Average_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 CCN_Facility_Name;
run;


ods _all_ close;
ods listing;

1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11

The attached code will create a page for each facility by looping over a list of the names extracted by proc sql.  I would even go further and create a single sgplot inside a macro that would create all 4 graphs

%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="&fn";
  		%graphit;
  		');
run;
ods _all_ close;
ods listing;

View solution in original post

3 REPLIES 3
Reeza
Super User

1. Remove the BY statement

2. Add a WHERE statement to filter for a single location. 

3. Make sure the graph and file is generated as needed.

4. Convert to a macro using the following approach

 


@sasroper wrote:

Hello,

My data set includes six months' of data for several different healthcare facilities.  I don't need to do any calculations, they've already been performed.  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.  I'm creating a total of 4 graphs for each facility, one for each of the measures I'm looking at.  How can I get the data to go through the sgplot so that each facility has all 4 graphs on a page together.  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.  I imagine I need to use a macro, but I'm stuck, as macros are a weakness for me.  I'm using SAS 9.4.  I've attached a dummy data set and this is the code I'm using:


options nodate nonumber orientation=landscape;

goptions reset=all device=sasprtc htitle=13pt ftext="Helvetica/bold";

ods _all_ close;
ods pdf file='data.pdf' notoc dpi=300 startpage=no;


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 = Average_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 CCN_Facility_Name;
run;


ods _all_ close;
ods listing;


 

sasroper
Calcite | Level 5
Thank you!! Both solutions worked for me. I really appreciate the help!
ghosh
Barite | Level 11

The attached code will create a page for each facility by looping over a list of the names extracted by proc sql.  I would even go further and create a single sgplot inside a macro that would create all 4 graphs

%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="&fn";
  		%graphit;
  		');
run;
ods _all_ close;
ods listing;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 567 views
  • 0 likes
  • 3 in conversation