Data visualization with SAS programming

How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

Accepted Solution Solved
Reply
SAS Employee
Posts: 6
Accepted Solution

How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

Dear SAS GRAPH community,

We are attempting to create specialized graphs using the following steps. Any ideas or help would be most appreciated.

step 1: We are creating 4 different box
plots from the following code which is using both  proc template and proc
sgrender.  Now we want to put these 4 boxplots adjacent to each
other on one sheet or one graphical output so that we can see all the 4
boxplots on one graph.

step 2 : The best way to show multiple
graphs on one output is to use proc greplay.Proc greplay uses the
grpahs that are produced and saved in a catalog.

Problem: How can I save the 4 graphs that
are produced in step 1 (using proc template and proc sgrender) to a catalog?

see the code below.

%let varlist=rebate std_bid plan_bid risk_score;

%macro chk;

         %let j=0;

         %do
%while(%scan(&varlist,&j+1,%str( )) ne %str( ));

         %let j = %eval(&j+1);

         %let var =
%scan(&varlist,&j,%str( ));

PROC SQL;

CREATE TABLE
WORK.&var.x1 AS

            SELECT
t1.year,               
t1.&var._min as min2,              
t1.&var._p10 as min,              
t1.&var._p25 as q1,              
t1.&var._median as median,               
t1.&var._mean as mean,                 
t1.&var._p75 as q3,               
t1.&var._p90 as max,                 
t1.&var._max as max2,               
t1.enrollment,                 
t1.state              
FROM WORK.NEW t1             
WHERE t1.year >= 2012                    
and t1._type_=32                  
and t1.state in (6,12,36,42)           
ORDER BY t1.state, t1.year;

         QUIT;

PROC TRANSPOSE DATA=WORK.&var.x1           
OUT=WORK.&var.x2

         (LABEL="Transposed Data
Set"  drop=newlabel rename=(col1=&var))          
PREFIX=Col        
NAME=quantile          
LABEL=newlabel  ;           
     BY state year;           
     VAR min q1 median mean q3 max;

RUN;

/*Producing boxplots*/

proc template;

     define statgraph
     boxplotparm1;            
     begingraph;               
     entrytitle "&var Levels";               
     layout overlay;                 
     boxplotparm y=&var x=area_yr stat=quantile/               
     meanattrs=(color=blue size=8px symbol=DiamondFilled weight=bold)              
     orient=horizontal;               
     endlayout;            
     endgraph;

      end;

run;

proc sgrender data=work.&var.x4 template=boxplotparm1;

         where enrollment>400000;

run;

%end;

%mend chk;

%chk;


Accepted Solutions
Solution
‎05-23-2012 10:57 AM
SAS Super FREQ
Posts: 1,081

Re: How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

You can use proc GSLIDE to put the image into a catalog, then play it in GREPLAY.  But that is likely not your best option.  In your macro you are creating separate graphs for each of the variables in the varlist.

  1. You could write the graphs into ODS Documents, and then play them onto ODS Layout.
  2. You could do the loop outside the macro, and then play each graph into an ODS Layout directly.
  3. You could set your data up so you have the variables in the varlist as a class variable in the data, with box data for each value.  Then, you could use a GTL DataPanel or DataLattice with this class variable, and create a grid, all within GTL.

View solution in original post


All Replies
Solution
‎05-23-2012 10:57 AM
SAS Super FREQ
Posts: 1,081

Re: How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

You can use proc GSLIDE to put the image into a catalog, then play it in GREPLAY.  But that is likely not your best option.  In your macro you are creating separate graphs for each of the variables in the varlist.

  1. You could write the graphs into ODS Documents, and then play them onto ODS Layout.
  2. You could do the loop outside the macro, and then play each graph into an ODS Layout directly.
  3. You could set your data up so you have the variables in the varlist as a class variable in the data, with box data for each value.  Then, you could use a GTL DataPanel or DataLattice with this class variable, and create a grid, all within GTL.
SAS Employee
Posts: 967

Re: How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

Note that there are several caveats when it comes to using GREPLAY with images...

First, you have to use an old grseg-based proc (such as GSLIDE that Sanjay mentioned) along with annotate or iback, etc to get the image into a grseg.  But you have to be very-very careful to get your size and proportions (x & y dimensions) of the original image just right, and then the size of your gslide just right (and annotate or iback in a way that doesn't stretch the image), and then the size of the final greplay output, in combination with the size of the custom areas where you greplay the images, must be "just right", for the images to look good.

If you stretch or distort the images out of proportion at any step along the way, the final graph can come out not looking so good.

Here's an example of a greplay dashboard, that was created by annotating images of graphs/indicators in gslides:

http://robslink.com/SAS/democd26/kpidash.htm

http://robslink.com/SAS/democd26/kpidash_info.htm

SAS Employee
Posts: 6

Re: How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

Thanks, Sanjay and Robert, for your quick and detailed responses.  I'm working on incorporating your answers today. I will report success or ask more questions as I progress through the solution.

--Matt

SAS Employee
Posts: 6

Re: How can I save multiple graphs produced by proc template and sgrender to a catalog so I can use them in proc greplay?

Sanjay and Robert,

Thanks, again. I used Sanjay's third suggestion and it worked very well. I appreciate the help.

--Matt


☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 377 views
  • 3 likes
  • 3 in conversation