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

I work with very large "stacked" time-series data and have found SGPLOT (using the "BY" command) works great to produce quality charts.  Currently SGPLOT outputs one chart for each of my BY elements.  The "BY" command is a powerful feature in SGPLOT, as I typically work with hundreds of distinct BY elements (i.e. makes "mass charting" possible).

 

I'd like to arrange the output charts "side by side" (2 charts, 3 charts, etc.).  I'm not creating HTML destination files, just viewing the "Results - HTML" window in my SAS EG (7.15) desktop.  Just need a simple solution that works in EG. 

 

  1. I started working with SGPANEL but I will have to completely modify my approach to data structure, so hoping I can avoid that.  Also, I want each individual chart to have independent Y-axis (given mix/match of different scales), which I couldn't solve in SGPANEL.  
  2. Another approach I saw involved ODS (ods layout gridded columns=2;  ).  However I couldn't get it to work with BY command in SGPLOT.  I think this may still be a good option, but need help getting it to work.  It seems like I need a way to "point" each chart output from "BY" command to a spot on the ODS Grid layout.  Probably a "Z" pattern (as dictated by "BY" sort).  

Below, part (1) is quick example to create "stacked" time-series data (to mimic what I use), and to produce the numerous charts.  part (2) tries to incorporate ODS commands however I am unable to get this to work.

 

(1) Code to generate stacked data, and illustrative SGPLOT

proc transpose data=sashelp.usecon out=stack; by date; run;

data stack; set stack;
format date mmddyy10.;
rename COL1=Value;
run;

proc sort data=stack; by _NAME_ date;run;

proc sgplot data=stack; by _NAME_;
series x=Date y=Value;  
title font=calibri bold color=black h=12pt '#byval1' ;
where Value ne .;
run;

(2) SGPLOT with ODS - failed attempt to create side-by-side using ODS layout Gridded Columns=2;

the charts appear similar as the stacked above (i.e. not side by side)

ods layout gridded columns=2;
ods graphics / width=600 height=450;
ods region;
ods html(eghtml);

proc sgplot data=stack; by _NAME_;
   series x=Date y=Value;  
   title font=calibri bold color=black h=12pt '#byval1' ;
   where Value ne .;
run;

ods layout end;

** I am only trying to view this in SAS EG's "Result - HTML" viewer -- not trying to create .html files.

 

THANKS for any help or suggestions to solving this.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

How about using ODS LAYOUT?  See some examples in this article.  I see you tried, but you might be missing some options.

 

There is an ADVANCE=BYGROUP directive that you should use to get the BY group output to advance to the next region.

 

Chris

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

View solution in original post

12 REPLIES 12
Reeza
Super User
Are you set on using HTML?
If you can use PDF there's a column option on the PDF statement that will split your page into three columns or two by default. Just makes sure to set your page size accordingly.
dsmall2112
Obsidian | Level 7
I might try the PDF option (can enable PDF Results viewer in EG to achieve similar-looking output). Would that be with ODS? Any coding examples you could share? 🙂
Reeza
Super User
ods pdf file = '/folders/myfolders/demo.pdf' columns=2 style=seaside;

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

proc sgplot data=cars;
by make;
scatter x=mpg_city y=mpg_highway;
run;

ods pdf close;

@dsmall2112 wrote:
I might try the PDF option (can enable PDF Results viewer in EG to achieve similar-looking output). Would that be with ODS? Any coding examples you could share? 🙂

 

dsmall2112
Obsidian | Level 7

Thanks @Reeza . 

 

I couldn't get the EG "results - PDF" viewer to reflect side-by-side, but I was able to use your code (specify an output PDF file on server) to get side-by-side (see uploaded PDF).  However, this only put 2 charts on a single page.  Is there any way to adjust to get (say 4 or 6)?  I do feel that the HTML picture quality is better than the PDF, although that may just be in settings.

 

Code using PDF output (via ODS):

ods pdf file = '/my_directory/charts_side-by-side_test.pdf' columns=2 style=seaside;

proc sgplot data=stack; by _NAME_ ;
series x=Date y=Value;    
title  font=calibri bold color=black h=12pt '#byval1' ;
where Value ne .;
run; 

ods pdf close;
PaigeMiller
Diamond | Level 26

@dsmall2112 wrote:

... However, this only put 2 charts on a single page.  Is there any way to adjust to get (say 4 or 6)?


You could use PROC SGPANEL.

--
Paige Miller
dsmall2112
Obsidian | Level 7

Thanks @PaigeMiller for your suggestion.  I did attempt SGPANEL but a couple of things about it that I didn't like (and haven't figured out how to overcome). 

  1. First was the Y-Axis scale needs to be independent.  So far as I can tell SGPANEL forces same Y axis scale, at least on a given row of charts.
  2. Second, the titles for charts needs some work (this may just require some refinement to get it to work as I'd like).  SGPANEL may yet work but I'll have to spend time resolving these obstacles. 

Continuing with my "stacked" structure, here's what I came up with using SGPANEL.

ods graphics on /width=8in height=4in;
proc sgpanel data=stack;
	panelby _NAME_ / columns=2 rows=1;
	series x=date y=value ;
	*X;colaxis grid;
	*Y;rowaxis grid;
run;  

 

ChrisHemedinger
Community Manager

How about using ODS LAYOUT?  See some examples in this article.  I see you tried, but you might be missing some options.

 

There is an ADVANCE=BYGROUP directive that you should use to get the BY group output to advance to the next region.

 

Chris

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
dsmall2112
Obsidian | Level 7

Thanks to everyone for your posts! 

 

@ChrisHemedinger  your response (advance=BYGROUP) was the answer I needed to use the ODS LAYOUT GRIDDED method.  Results were excellent. 

 

I do need to solve how to TITLE each chart now (title statements in the PROC SGPLOT only work on the 1st chart; charts 2-N have no title).  I'm sure this is buried within the ODS coding (ODS Text ?) so that will be my next challenge. 

 

Below is the updated ODS code, using advance=BYGROUP:

 

*-----(1) Generate Stacked Time-Series Data----------------;
proc transpose data=sashelp.usecon out=stack; by date; run;

data stack; set stack;
format date mmddyy10.;
rename COL1=Value;
run;

proc sort data=stack; by _NAME_ date;run;
 
*-----(2) Begin ODS LAYOUT GRIDDED ----------------;
ods layout gridded columns=2 advance=bygroup;
ods graphics on /width=4in height=3in;
ods region;
ods html(eghtml);

*-----(3) Output charts----------------;
proc sgplot data=stack; by _NAME_ ;
series x=Date y=Value;    
*title  font=calibri bold color=black h=12pt '#byval1' ;*titles not working in ODS;
where Value ne .;
run; 
*-----(4) End ODS LAYOUT GRIDDED ----------------;
ods layout end;

 

ChrisHemedinger
Community Manager

@dsmall2112 Try changing your ODS HTML to:

 

  

ods html(eghtml) gtitle;
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
dsmall2112
Obsidian | Level 7

Thanks @ChrisHemedinger .

 

I added the GTITLE option, but still did not work.  SAS Documentation indicates GTITLE has TITLE restrictions (so I'm wondering if #BYVAL method may not be supported).

 

Here is the updated code (from previous example):

ods layout gridded columns=2 advance=bygroup;
ods graphics on /width=4in height=3in;
ods region;
ods html(eghtml) gtitle;

proc sgplot data=stack; by _NAME_ ;
series x=Date y=Value;    
title "#byval1" ;*does no work with ODS LAYOUT GRIDDED / GTITLE option;*single quotes don't work either;
where Value ne .;
run; 

ods layout end;

Of course, this method is new to me so I might need to research (or reach out to SAS Support to confirm a restriction).  If I resolve, I will post here.

ChrisHemedinger
Community Manager

This worked for me with SAS 9.4 M4.  Does #BYLINE do what you need?

 

proc sort data=sashelp.cars out=cars;
 by make;
run;
title;
ods layout gridded columns=2 advance=bygroup;
ods graphics on /width=4in height=3in;
ods region;
ods html(eghtml) gtitle;

title "MSRP vs INVOICE: #byline";
proc sgplot data=cars; by make ;
scatter x=msrp y=invoice;
run; 
ods layout end;

byline.png

 

Otherwise, there might be some tricks you can do with TEXT plot.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 12 replies
  • 1908 views
  • 2 likes
  • 4 in conversation