Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tips & Tricks MASUG02/18/2005. Multiple Graphs on One Page.

Similar presentations


Presentation on theme: "Tips & Tricks MASUG02/18/2005. Multiple Graphs on One Page."— Presentation transcript:

1 Tips & Tricks MASUG02/18/2005

2 Multiple Graphs on One Page

3 Often it is useful to put several or even many graphs on one page Often it is useful to put several or even many graphs on one page Graphs are created first and stored in a SAS graphics catalog Graphs are created first and stored in a SAS graphics catalog Using proc greplay a template can be defined and graphic elements put into the various panels Using proc greplay a template can be defined and graphic elements put into the various panels

4 Defining a template can be tedious Here is the template definition code for a sample 3 panel template: Here is the template definition code for a sample 3 panel template: tdef mytemp tdef mytemp 1 / llx=0 ulx=0 lrx=100 urx=100 lly=0 lry=0 uly=100 ury=100 1 / llx=0 ulx=0 lrx=100 urx=100 lly=0 lry=0 uly=100 ury=100 2 / llx=0 ulx=0 lrx=100 urx=100 lly=65 lry=65 uly=95 ury=95 2 / llx=0 ulx=0 lrx=100 urx=100 lly=65 lry=65 uly=95 ury=95 3 / llx=0 ulx=0 lrx=100 urx=100 lly=35 lry=35 uly=65 ury=65 ; 3 / llx=0 ulx=0 lrx=100 urx=100 lly=35 lry=35 uly=65 ury=65 ; Rather than define the two opposite corners of a rectangle (to define a panel), SAS wants the user to define all four corners of each rectangle (each panel). Rather than define the two opposite corners of a rectangle (to define a panel), SAS wants the user to define all four corners of each rectangle (each panel). Each (x,y) value is repeated twice, opening the door to human error. (Yes, I’ve seen templates with “crooked” panels.) Each (x,y) value is repeated twice, opening the door to human error. (Yes, I’ve seen templates with “crooked” panels.)

5 PanelDef /********************************************************************* * Name: PanelDef * * Desc: Returns the text for a greplay panel definition. * * Type: Graphics Utility * * History: * * 7/1/04 WJS * *********************************************************************/ %macro paneldef( pnlnbr, leftx, rightx, lowery, uppery, color ); %local return; %local return; %let return = &pnlnbr /; %let return = &pnlnbr /; %let return = &return llx=&leftx ulx=&leftx lrx=&rightx urx=&rightx; %let return = &return llx=&leftx ulx=&leftx lrx=&rightx urx=&rightx; %let return = &return lly=&lowery lry=&lowery uly=&uppery ury=&uppery; %let return = &return lly=&lowery lry=&lowery uly=&uppery ury=&uppery; %if ( %length( &color ) > 0 ) %then %if ( %length( &color ) > 0 ) %then %let return = &return color=&color; %let return = &return color=&color;&return%mend;

6 Sample Code goptions nodisplay; goptions nodisplay; proc gplot data=rpt gout=&mygout; proc gplot data=rpt gout=&mygout; plot &var * &timevar = 9 / plot &var * &timevar = 9 / grid frame autovref grid frame autovref vaxis = axis1 vaxis = axis1 haxis = axis2 haxis = axis2 name = "Top“ ; name = "Top“ ; plot &var * fmonth = fyear / plot &var * fmonth = fyear / grid frame autovref grid frame autovref vaxis = axis1 vaxis = axis1 haxis = axis3 haxis = axis3 legend = legend1 legend = legend1 name = "RRTrks“ ; name = "RRTrks“ ; run; run;[snip] goptions display; goptions display; proc greplay nofs tc=mytcat igout=&mygout; proc greplay nofs tc=mytcat igout=&mygout; tdef mytemp tdef mytemp %panelDef( 1,0,100,0,100) %panelDef( 1,0,100,0,100) %panelDef( 2,0,100,&lowery1,&uppery1) %panelDef( 2,0,100,&lowery1,&uppery1) %panelDef( 3,0,100,&lowery2,&uppery2) ; %panelDef( 3,0,100,&lowery2,&uppery2) ; template mytemp; template mytemp; treplay treplay 1:titles 1:titles 2:Top 2:Top 3:RRTrks ; 3:RRTrks ; run; run;

7 Three Macros to Simplify Annotations

8 The SAS annotate facility give great flexibility in writing or drawing things on graphs – even producing specialized graphs The SAS annotate facility give great flexibility in writing or drawing things on graphs – even producing specialized graphs Typically, simple text is “dropped” onto a graph Typically, simple text is “dropped” onto a graph Learning annotate is not difficult but takes time Learning annotate is not difficult but takes time

9 Three simple macros can help Macro avars creates the basic variable needed in a dataset to annotate a graph Macro avars creates the basic variable needed in a dataset to annotate a graph Macro xyhsys specifies a “coordinate system” Macro xyhsys specifies a “coordinate system” Macro alabel defines a text label, placed anywhere you need it Macro alabel defines a text label, placed anywhere you need it

10 First an example The following code defines a “graph” that has the titles for a Multi-graph page: The following code defines a “graph” that has the titles for a Multi-graph page: data annotitles; data annotitles; %avars %avars %xyhsys( 1,1,1 ) %xyhsys( 1,1,1 ) %alabel( 50,100, "&title1",,,, 3.5, centb,E ) %alabel( 50,100, "&title1",,,, 3.5, centb,E ) %alabel( 50,95, "&title2",,,, 2.5, centb,E ) %alabel( 50,95, "&title2",,,, 2.5, centb,E ) run; run; proc ganno annotate=annotitles gout=&mygout name='titles'; proc ganno annotate=annotitles gout=&mygout name='titles'; run; run;

11 avars /*********************************************************** * Name: avars * * Desc: Annotate macro to declare and size standard * * annotate dataset variables * * Type: Graphics Utility - Annotate Macro * * Walt Smith May 10, 2001 * ***********************************************************/ %macro avars; length color function style $8; length color function style $8; length text $200; length text $200; length x y 8; length x y 8;%mend;

12 xyhsys /**************************************************************** * Name: xyhsys * * Desc: Annotate macro to set the value of three annotate * * variables: xsys, ysys, and hsys. * * Type: Graphics Utility - Annotate Macro * *---------------------------------------------------------------* * ============================================= * * | Table of Coordinate System Codes | * * | (See SAS/Graph Software pg 476) | * * +-----------+---------+----------+----------+ * * | Area | Units | Absolute | Relative | * * +-----------+---------+----------+----------+ * * | Data | % | 1 | 7 | * * | Area | Values | 2 | 8 | * * +-----------+---------+----------+----------+ * * | Graphics | % | 3 | 9 | * * | Output | Cells | 4 | A | * * | Area | | | | * * +-----------+---------+----------+----------+ * * | Procedure | % | 5 | B | * * | Output | Cells | 6 | C | * * | Area | | | | * * ============================================= * ****************************************************************/ %macro xyhsys( xsys, ysys, hsys ); xsys = "&xsys"; xsys = "&xsys"; ysys = "&ysys"; ysys = "&ysys"; hsys = "&hsys"; hsys = "&hsys";%mend;

13 alabel /*********************************************************** * Name: alabel * * Desc: Annotate macro to place text on a graph * * Type: Graphics Utility - Annotate Macro * * * * Walt Smith November 30, 1999 * * 5/8/02 WJS Modify logic for pos parm * ***********************************************************/ %macro alabel (x,y,txt,coltxt,ang,rot,size,font,pos); %if ( %length( &x ) >0 ) %then x = &x %str(;); %if ( %length( &x ) >0 ) %then x = &x %str(;); %if ( %length( &y ) >0 ) %then y = &y %str(;); %if ( %length( &y ) >0 ) %then y = &y %str(;); %if ( %length( &ang ) >0 ) %then angle = &ang %str(;); %if ( %length( &ang ) >0 ) %then angle = &ang %str(;); %if ( %length( &rot ) >0 ) %then rotate = &rot %str(;); %if ( %length( &rot ) >0 ) %then rotate = &rot %str(;); %if ( %length( &size ) >0 ) %then size = &size%str(;); %if ( %length( &size ) >0 ) %then size = &size%str(;); %if ( %length( &txt ) >0 ) %then text = &txt %str(;); %if ( %length( &txt ) >0 ) %then text = &txt %str(;); %if ( %length( &font ) >0 ) %then style = "&font"%str(;); %if ( %length( &font ) >0 ) %then style = "&font"%str(;); %if ( %length( &pos ) =1 ) %then position = "&pos"%str(;); %if ( %length( &pos ) =1 ) %then position = "&pos"%str(;); %else %if ( %length( &pos ) > 1 ) %then position = &pos %str(;); %else %if ( %length( &pos ) > 1 ) %then position = &pos %str(;); %if %length(&coltxt)>0 %then color = "&coltxt"%str(;); %if %length(&coltxt)>0 %then color = "&coltxt"%str(;); function='label'; function='label'; output; output;%mend;

14 PROC SQL vs. PROC MEANS by John Ang Senior Merchandising Analyst AutoZone

15 Summary Functions in PROC SQL The following summary functions are available when using PROC SQL: AVG COUNT MIN MAX STD SUM VAR The GROUP BY statement is used in conjunction with these summary functions.

16 PROC SQL Query proc sql; create table boo as select hoo, sum(foo) as goo from doo group by hoo; quit;

17 Output Statistics in PROC MEANS The following output statistics are available when using PROC SQL: MEAN N MIN MAX STD SUM VAR The OUTPUT statement is used in conjunction with these output statistics.

18 PROC MEANS Query proc means data=doo sum mean noprint; class hoo; var foo; output out=boo sum=goo; run;

19 Comparison of SAS Log 135 proc sql; 136 create table boo as 137 select hoo, sum(foo) as goo 138 from doo 139 group by hoo; NOTE: Table WORK.BOO created, with 18607 rows and 2 columns. 140 quit; NOTE: PROCEDURE SQL used: real time 1:15.31 cpu time 46.82 seconds 141 proc means data=doo sum mean noprint; 142 class hoo; 143 var foo; 144 output out=boo2 sum=goo; 145 run; NOTE: There were 20532029 observations read from the data set DAD5DATA.SSPOLK. NOTE: The data set WORK.BOO2 has 18608 observations and 2 variables. NOTE: PROCEDURE MEANS used: real time 39.10 seconds cpu time 34.89 seconds

20 Another Example proc means data=limahl.omd sum noprint; class time; var edge; output out=sting1 sum=toto; run; proc sql; create table sting2 as select time, sum(edge) as toto from limahl.omd group by time; quit;

21 Another SAS Log 3 proc means data=limahl.omd sum noprint; 4 class time; 5 var edge; 6 output out=sting1 sum=toto; 7 run; NOTE: There were 444186953 observations read from the data set SREGDATA.VITEMADJ_DOWNLOAD. NOTE: The data set WORK.STING1 has 158234 observations and 4 variables. NOTE: PROCEDURE MEANS used: real time 23:16.58 cpu time 12:52.62 8 9 proc sql; 10 create table sting2 as 11 select time, sum(edge) as toto 12 from limahl.omd 13 group by time; NOTE: Table WORK.STING2 created, with 158233 rows and 2 columns. 14 quit; NOTE: PROCEDURE SQL used: real time 50:50.62 cpu time 23:33.05

22 PROC SQL or PROC MEANS? PROC SQL code can be more readable and easily understood by other SAS users. Generally, PROC MEANS will produce the same summarized result in less CPU time than PROC SQL will. More descriptive statistics (e.g. quantiles) are available with PROC MEANS than with PROC SQL.


Download ppt "Tips & Tricks MASUG02/18/2005. Multiple Graphs on One Page."

Similar presentations


Ads by Google