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.
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.
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
You could use PROC SGPANEL
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? 🙂
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;
@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.
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).
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;
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
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;
@dsmall2112 Try changing your ODS HTML to:
ods html(eghtml) gtitle;
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.
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;
Otherwise, there might be some tricks you can do with TEXT plot.
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!
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.
Ready to level-up your skills? Choose your own adventure.