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

Hi,

 

I am trying to get ODS PDF to loop through three SGPLOT procedures for each BY group, which comes from a list in a separate table containing the subset of BY groups I want to use. 

 

The below example uses SASHELP.CARS, but the applications could be employee scorecards, business unit reports, etc. The first data step creates a table of BY groups (selectedmakes) to be used in the following SGPLOTs. The goal would be to have six total pages with three plots each (one for BMW, one for Chevrolet, etc.). If the answer is to "just make a macro do loop," please explain the method or provide a solution using the example code. I have tried to study how to do this but have had trouble understanding to this point.

 

data selectedmakes;
	format selectedmake $20.;
	input index selectedmake $;
	cards;
	1 BMW
	2 Chevrolet
	3 Ford
	4 Jaguar
	5 Mercury
	6 Pontiac
	;
run;


options printerpath=PDF;
goptions device=SASPRTC;
ods graphics on / reset=all;
ods pdf gtitle startpage=no notoc dpi=300;
ods graphics / height=3in width=6in;
options nobyline;

proc sgplot data=sashelp.cars;
	title "Highway MPG by Type";
	title2 "Make: #byval1";
	vbox mpg_highway / category = type;
	yaxis values = (0 to 40 by 5) label = "Highway MPG";
	by make;
run;

proc sgplot data=sashelp.cars;
	title "Invoice vs. MSRP";
	title2 "Make: #byval1";
	scatter x = invoice y = msrp;
	xaxis values = (0 to 100000 by 20000) label = "Invoice";
	yaxis values = (0 to 100000 by 20000) label = "MSRP";
	by make;
run;

proc sgplot data=sashelp.cars;
	title "Horsepower by Engine Cylinders by Type";
	title2 "Make: #byval1";
	vbox horsepower / category = cylinders group = type;
	yaxis values = (0 to 500 by 100) label = "Horsepower";
	by make;
run;

ods pdf close;

 

Thanks for your help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data selectedmakes;
	format selectedmake $20.;
	input index selectedmake $;
	cards;
	1 BMW
	2 Chevrolet
	3 Ford
	4 Jaguar
	5 Mercury
	6 Pontiac
	;
run;





%macro create_graphs(make=);
ods pdf startpage=now;
proc sgplot data=sashelp.cars;
	title "Highway MPG by Type";
	title2 "Make: &make.";
	where make = "&make";
	vbox mpg_highway / category = type;
	yaxis values = (0 to 40 by 5) label = "Highway MPG";

run;

proc sgplot data=sashelp.cars;
	title "Invoice vs. MSRP";
	title2 "Make: &make.";
	where make = "&make";
	scatter x = invoice y = msrp;
	xaxis values = (0 to 100000 by 20000) label = "Invoice";
	yaxis values = (0 to 100000 by 20000) label = "MSRP";

run;

proc sgplot data=sashelp.cars;
	title "Horsepower by Engine Cylinders by Type";
	title2 "Make: &make.";
	where make = "&make";
	vbox horsepower / category = cylinders group = type;
	yaxis values = (0 to 500 by 100) label = "Horsepower";

run;

%mend;

ods pdf file = '/home/fkhurshed/Demo1/singlePage.pdf' gtitle notoc dpi=300 startpage=never;

options printerpath=PDF;
goptions device=SASPRTC;
ods graphics on / reset=all;

ods graphics / height=3in width=6in;
options nobyline;


data _null_;
set selectedmakes;
str = catt('%create_graphs(make=',selectedmake, ');') ;
call execute(str);
run;

ods pdf close;

https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

 


@Thummim wrote:

Hi,

 

I am trying to get ODS PDF to loop through three SGPLOT procedures for each BY group, which comes from a list in a separate table containing the subset of BY groups I want to use. 

 

The below example uses SASHELP.CARS, but the applications could be employee scorecards, business unit reports, etc. The first data step creates a table of BY groups (selectedmakes) to be used in the following SGPLOTs. The goal would be to have six total pages with three plots each (one for BMW, one for Chevrolet, etc.). If the answer is to "just make a macro do loop," please explain the method or provide a solution using the example code. I have tried to study how to do this but have had trouble understanding to this point.

 

data selectedmakes;
	format selectedmake $20.;
	input index selectedmake $;
	cards;
	1 BMW
	2 Chevrolet
	3 Ford
	4 Jaguar
	5 Mercury
	6 Pontiac
	;
run;


options printerpath=PDF;
goptions device=SASPRTC;
ods graphics on / reset=all;
ods pdf gtitle startpage=no notoc dpi=300;
ods graphics / height=3in width=6in;
options nobyline;

proc sgplot data=sashelp.cars;
	title "Highway MPG by Type";
	title2 "Make: #byval1";
	vbox mpg_highway / category = type;
	yaxis values = (0 to 40 by 5) label = "Highway MPG";
	by make;
run;

proc sgplot data=sashelp.cars;
	title "Invoice vs. MSRP";
	title2 "Make: #byval1";
	scatter x = invoice y = msrp;
	xaxis values = (0 to 100000 by 20000) label = "Invoice";
	yaxis values = (0 to 100000 by 20000) label = "MSRP";
	by make;
run;

proc sgplot data=sashelp.cars;
	title "Horsepower by Engine Cylinders by Type";
	title2 "Make: #byval1";
	vbox horsepower / category = cylinders group = type;
	yaxis values = (0 to 500 by 100) label = "Horsepower";
	by make;
run;

ods pdf close;

 

Thanks for your help!

 


 

View solution in original post

2 REPLIES 2
Reeza
Super User
data selectedmakes;
	format selectedmake $20.;
	input index selectedmake $;
	cards;
	1 BMW
	2 Chevrolet
	3 Ford
	4 Jaguar
	5 Mercury
	6 Pontiac
	;
run;





%macro create_graphs(make=);
ods pdf startpage=now;
proc sgplot data=sashelp.cars;
	title "Highway MPG by Type";
	title2 "Make: &make.";
	where make = "&make";
	vbox mpg_highway / category = type;
	yaxis values = (0 to 40 by 5) label = "Highway MPG";

run;

proc sgplot data=sashelp.cars;
	title "Invoice vs. MSRP";
	title2 "Make: &make.";
	where make = "&make";
	scatter x = invoice y = msrp;
	xaxis values = (0 to 100000 by 20000) label = "Invoice";
	yaxis values = (0 to 100000 by 20000) label = "MSRP";

run;

proc sgplot data=sashelp.cars;
	title "Horsepower by Engine Cylinders by Type";
	title2 "Make: &make.";
	where make = "&make";
	vbox horsepower / category = cylinders group = type;
	yaxis values = (0 to 500 by 100) label = "Horsepower";

run;

%mend;

ods pdf file = '/home/fkhurshed/Demo1/singlePage.pdf' gtitle notoc dpi=300 startpage=never;

options printerpath=PDF;
goptions device=SASPRTC;
ods graphics on / reset=all;

ods graphics / height=3in width=6in;
options nobyline;


data _null_;
set selectedmakes;
str = catt('%create_graphs(make=',selectedmake, ');') ;
call execute(str);
run;

ods pdf close;

https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

 


@Thummim wrote:

Hi,

 

I am trying to get ODS PDF to loop through three SGPLOT procedures for each BY group, which comes from a list in a separate table containing the subset of BY groups I want to use. 

 

The below example uses SASHELP.CARS, but the applications could be employee scorecards, business unit reports, etc. The first data step creates a table of BY groups (selectedmakes) to be used in the following SGPLOTs. The goal would be to have six total pages with three plots each (one for BMW, one for Chevrolet, etc.). If the answer is to "just make a macro do loop," please explain the method or provide a solution using the example code. I have tried to study how to do this but have had trouble understanding to this point.

 

data selectedmakes;
	format selectedmake $20.;
	input index selectedmake $;
	cards;
	1 BMW
	2 Chevrolet
	3 Ford
	4 Jaguar
	5 Mercury
	6 Pontiac
	;
run;


options printerpath=PDF;
goptions device=SASPRTC;
ods graphics on / reset=all;
ods pdf gtitle startpage=no notoc dpi=300;
ods graphics / height=3in width=6in;
options nobyline;

proc sgplot data=sashelp.cars;
	title "Highway MPG by Type";
	title2 "Make: #byval1";
	vbox mpg_highway / category = type;
	yaxis values = (0 to 40 by 5) label = "Highway MPG";
	by make;
run;

proc sgplot data=sashelp.cars;
	title "Invoice vs. MSRP";
	title2 "Make: #byval1";
	scatter x = invoice y = msrp;
	xaxis values = (0 to 100000 by 20000) label = "Invoice";
	yaxis values = (0 to 100000 by 20000) label = "MSRP";
	by make;
run;

proc sgplot data=sashelp.cars;
	title "Horsepower by Engine Cylinders by Type";
	title2 "Make: #byval1";
	vbox horsepower / category = cylinders group = type;
	yaxis values = (0 to 500 by 100) label = "Horsepower";
	by make;
run;

ods pdf close;

 

Thanks for your help!

 


 

Thummim
Calcite | Level 5

Thank you for the solution and helpful article!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 433 views
  • 1 like
  • 2 in conversation