BookmarkSubscribeRSS Feed
magicdj
Obsidian | Level 7

  I need to put several line plots in one page, in rft format. I searched several posts but they are only working in pdf.

I made some codes below, but not sure how to apply if condition in gtl. also I want to different color for each model in line plots.

any help? thanks a lot.

 

ods _all_ close;

* set papersize etc. for PDF ;
options orientation=LANDSCAPE;


data cars;
  set sashelp.cars;


  run;



*;
ods rtf file="c:\individual_rtftet.rtf";



proc template;
  define statgraph plot_linearlog;
    begingraph;

      layout lattice / rows = 2 columns = 3;
if (make='Acura' )
        layout overlay / xaxisopts=(type = linear);
		
       seriesplot x= Horsepower y=MPG_City / name="series" ;
     endlayout;
endif;
		if (make='Audi' )
 
        layout overlay / xaxisopts=(type = linear);
      seriesplot x= Horsepower y=MPG_City / name="series" ;
     endlayout;
endif;

	if (make='BMW' )
 
        layout overlay / xaxisopts=(type = linear);
      seriesplot x= Horsepower y=MPG_City / name="series" ;
     endlayout;
endif;

	if (make='Buick' )
 
        layout overlay / xaxisopts=(type = linear);
      seriesplot x= Horsepower y=MPG_City / name="series" ;
     endlayout;
endif;
   endlayout;
 endgraph;
  end;
run;
quit;

proc sgrender data = sashelp.cars template = plot_linearlog;
run;

ods rtf close;

11 REPLIES 11
ballardw
Super User

Before going to all that (repetitive) coding in GTL I suggest looking at Proc SGPANEL first.

Example

proc sort data=sashelp.cars
   out=work.cars
;
   by make horsepower;
run;


proc sgpanel data=work.cars;
  where make in ('Acura' 'BMW' 'Buick');
  panelby make / columns=1
  ;
  series x=horsepower y=mpg_city;
run;

You could use a DATTRMAP data set to assign colors/ line types if you add a / group=Make to series statement.

 

If you have more than 2 or 3 levels for your actual data you may have to adjust the image size with an ODS Graphics statement setting height or width.

 

 

magicdj
Obsidian | Level 7

well, I prefer them separate than one panel. also. I need to show different models info within  a make.

if I have no choice, then I have to use proc sgpanel.

DanH_sas
SAS Super FREQ

How do you want to represent the additional model info within each cell?

magicdj
Obsidian | Level 7

individual line plot, each make has different models, each model has a different line.

DanH_sas
SAS Super FREQ

Using a variation of @ballardw 's program, and the layout you have in you GTL template, the code would look something like the following:

 

proc sort data=sashelp.cars
   out=work.cars;
   by make model horsepower;
run;


proc sgpanel data=work.cars;
  panelby make / columns=3 rows-2;
  series x=horsepower y=mpg_city / group=model;
run;

You can also using the SPACING option on the PANELBY statement to create space between the cells, which sounds like something you wanted. It is also possible to create a similar output using GTL using the DATAPANEL layout, but you can do it with less code using SGPANEL.

 

Hope this helps!

Dan

magicdj
Obsidian | Level 7

the problem is that different plots prefer to have different scale. sgpanel  only has fixed scale on left side, even using spacing option.

not each cell have it's own scale.

for GTL, I don't know how to use IF option. my code in first post is not working properly.

 

thanks for your help.

DanH_sas
SAS Super FREQ

Ah, I didn't realize that independent scale per plot was an issue for you. In that case, neither SGPANEL nor DATAPANEL will works for you, The GTL "if" conditional logic will not work for you either, in this case. What version of SAS do you have? if SAS 9.4, which maintenance version?

magicdj
Obsidian | Level 7

I use SAS 9.4, have no idea about maintenance version and don't know where to check maintenance version

ballardw
Super User

@magicdj wrote:

the problem is that different plots prefer to have different scale. sgpanel  only has fixed scale on left side, even using spacing option.

not each cell have it's own scale.

for GTL, I don't know how to use IF option. my code in first post is not working properly.

 

thanks for your help.


The PANELBY option UNISCALE sets which axes are identical. The default is all but if you use UNISCALE=COLUMN only the X axis will have the same scale within each row. So with a single column each panel would likely have a separate Y axis if the data required it.

magicdj
Obsidian | Level 7

I have 2 row and 2 column panel, so this option won't work for me.

I curious one thing. I have 2 row and 2 column format, if I have extra plot, for example 5 or 7 plots, it produced an empty cell in last row, anyone know how to get ride of empty cell? thanks a lot.

magicdj
Obsidian | Level 7

I got it, use skipemptycells to get ride of it.Smiley Happy

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1790 views
  • 0 likes
  • 3 in conversation