Data visualization with SAS programming

How to create 4 charts in a single row with in a single page

Reply
Frequent Contributor
Posts: 117

How to create 4 charts in a single row with in a single page

Hi,

I want to create 4 charts in a single row, then below that i need to display the data used . My requirement is to get in Excel as well in pdf. when i create using ods lay out and regions, i am getting in html report output but in the excel sheet the charts are not displayed only data is available. As well the pdf output is not matching with my requirement. I am getting all the charts in different pages.

please look into the below code and suggest me if any changes.

ods listing close;

ods pdf  file="/myfolder/&cmpy&yymm..pdf";

ods html file="/ myfolder /&cmpy&yymm..xls";

goptions reset=global gunit=pct border

colors=(blue blue blue yellow)

ctext=black cback=cxCCFFFF

hsize=3in vsize=3in ftitle=zapfb

ftext=swiss htitle=6 htext=4

device=gif transparency;

Axis1 STYLE=2 WIDTH=2 MINOR= (NUMBER=2);

Axis2 STYLE=5 WIDTH=5;

ods layout start width=10in height=8in columns=4 rows=2

                 column_gutter=.5in row_gutter=.8in row_heights=(3.5in 3.5in);

ods region row=1 column=1;

PROC GCHART DATA=final1;

      VBAR3D

       MONTH/ descending

      SUMVAR=avg_speed_to_answer

      SHAPE=BLOCK

FRAME TYPE=SUM

      LEGEND=LEGEND1

      COUTLINE=BLACK

      RAXIS=AXIS1

      MAXIS=AXIS2

PATTERNID=MIDPOINT

width=15

inside=sum

coutline=black

cframe=white

;

RUN; QUIT;

ods region row=1 column=2;

PROC GCHART DATA=final2;

      VBAR3D

       MONTH/ descending

      SUMVAR=avg_talk_time

      SHAPE=BLOCK

FRAME TYPE=SUM

      LEGEND=LEGEND1

      COUTLINE=BLACK

      RAXIS=AXIS1

      MAXIS=AXIS2

PATTERNID=MIDPOINT

width=15

inside=sum

coutline=black

cframe=white

;

RUN; QUIT;

ods region row=1 column=3;

PROC GCHART DATA=final3;

      VBAR3D

       MONTH/ descending

      SUMVAR=answered_cnt

      SHAPE=BLOCK

FRAME TYPE=SUM

      LEGEND=LEGEND1

      COUTLINE=BLACK

      RAXIS=AXIS1

      MAXIS=AXIS2

PATTERNID=MIDPOINT

width=15

inside=sum

coutline=black

cframe=white

;

RUN; QUIT;

ods region row=1 column=4;

PROC GCHART DATA=final4;

      VBAR3D

       MONTH/ descending

      SUMVAR=answered_cnt

      group=abondoned_cnt

      SHAPE=BLOCK

FRAME TYPE=SUM

      LEGEND=LEGEND1

      COUTLINE=BLACK   

      RAXIS=AXIS1

      MAXIS=AXIS2

PATTERNID=MIDPOINT

width=15

inside=sum

coutline=black

cframe=white

;

RUN; QUIT;

ods region row=2 column=2;

proc report data=all style(header)=[BACKGROUND =blue BORDERRIGHTCOLOR=blue BORDERTOPCOLOR=white foreground=white BORDERCOLOR=blue font = (Arial,10pt) font_weight = bold];

run;

ods layout end;

ods pdf close;

ods _all_ close;




Grand Advisor
Posts: 10,239

Re: How to create 4 charts in a single row with in a single page

There are at least two ways that may work to get your charts "on a row". With GCHART output it helps to specify a common output catalog using gout=library.catalog . The create and use a template created for use with Proc Greplay. Since this approach reduces sizes of fonts and such it might be better to use Proc sgpanel as that allows some control of rows and columns of charts but will probably require reshaping your data.

Occasional Contributor
Posts: 8

Re: How to create 4 charts in a single row with in a single page

What version of SAS are you using?  If you are using 9.2, by far the easiest way is to use the GTL and sgrender to layout your graphs on a page.  When you do this you do not need to use the layout statement at all.

You might want to reference this article http://support.sas.com/resources/papers/proceedings10/035-2010.pdf - you will see that you now have to define the specific region size.  This will work for PDF, but XLS is an issue  - see Cynthia's post re outputing graphics to XLS.  I haven't found a good way that works with all the other features I want such a multiple tabs.  If you use MSOFFICE2K  - you can embed images. 

Super Contributor
Posts: 543

Re: How to create 4 charts in a single row with in a single page

Hi,

If you cannot use SGPANEL then you are left with the PROC GREPLAY option.

In order to use this PROC you need to assign a name to each of your four charts by adding the option  name = "first" (or name = "second") ...

PROC GCHART DATA=final4;

      VBAR3D

       MONTH/ descending  name = "fourth"

      SUMVAR=answered_cnt

      group=abondoned_cnt

      SHAPE=BLOCK

FRAME TYPE=SUM

      LEGEND=LEGEND1

      COUTLINE=BLACK   

      RAXIS=AXIS1

      MAXIS=AXIS2

PATTERNID=MIDPOINT

width=15

inside=sum

coutline=black

cframe=white

;

RUN; QUIT;


You will then have to invoke PROC GREPLAY three times. Each of these times you will use the "h2" template, which is 2 horizontal plots. You also need to "adjust" the graphing window accordingly, thus making the horizontal line 6 inches, and the vertical one stays 3 inches.

goptions hsize = 6in vsize = 3in;

proc greplay igout = work.gseg

  tc = sashelp.templt template = h2

    nofs nobyline ;

    treplay 1Smiley Surprisedne 2:two;

run;quit;

goptions hsize = 6in vsize = 3in;

proc greplay igout = work.gseg

  tc = sashelp.templt template = h2

    nofs nobyline ;

    treplay 1:three 2:four;

run;quit;

Both of these GREPLAY PROCs will produce 'template" and "templat1" in your work.gseg folde

goptions reset = all;

options orientation = landscape;

ods pdf file = "&path.\test.pdf";

goptions device = pdf rotate = landscape gsfmode = replace

       hsize = 12in vsize = 3in;

proc greplay igout = work.gseg

  tc = sashelp.templt template = h2

    nofs nobyline ;

    treplay 1:template 2:templat1;

run;quit;

ods pdf close;

The downsize of this approach is that everytime you run your PROC GCHART/GREPLAY you will first need to delete the content of your work.gseg folder, otherwise you will get a warning such as,

"Graph's name, FOUR, changed to FOUR1. FOUR is already used or not a valid SAS name."

A way to fix this would be to use

proc greplay igout = work gseg nofs;

     delete _all_;

run;quit;

All the best!


Ask a Question
Discussion stats
  • 3 replies
  • 322 views
  • 0 likes
  • 4 in conversation