Download presentation
Presentation is loading. Please wait.
Published byChad Watkins Modified over 8 years ago
1
SAS Graphical Macros February 17, 2016 Rocio Lopez
2
Overview Color utility macros Annotation macros Template modification macros Graphical macros Where to find each macro
3
COLOR UTILITY MACROS
4
Color utility macros Set of 10 macros to manage color names To initiate the macros in your current session you call the %COLORMAC macro To get help on any macro call the %HELPCLR macro %colormac; %helpclr(ALL|macro-name); This will print out help information to the log file
5
%RGB %RGB(red, green, blue); Creates an RGB color name from the numeric RGB component values Example: %colormac; %put %rgb(255, 0, 0) is red; This will print out to the log: CXFF0000 is red
6
%RGB You can run this macro from within SGPLOT, SGPANEL or GTL proc sgplot data=sashelp.class noborder; scatter x=height y=weight/ markerattrs=(color=%rgb(255, 0, 0) size=10 symbol=CircleFilled); run;
7
Other available color utility macros MacroDescription %CMY(cyan, magenta, yellow); Creates an RGB color name from numeric CMY components %CMYKCMY(cyan, magenta, yellow, black); Creates an CMYK color name from numeric CMYK components %CNS(cns-color-name); Creates a HLS color name from a color-naming scheme (CLS) color name %HLS(hue, lightness, saturation); Creates an HLS color name from numeric HLS component values %HSV(hue, saturation, value); Creates an HLS color name from numeric HSV components %HLS2RGB(hls-color-name); Creates and RGB color name from an HLS color name %RGB2HLS(rgb-color-name); Creates and HLS color name from an RGB color name https://support.sas.com/documentation/cdl/en/graphref/67881/HTML/default/viewer.htm#n0z9vlsy95ug xcn1qchqznw88m6e.htm
8
ANNOTATION MACROS
9
SG Annotation Mechanism to add – Text labels – Lines and arrows – Ovals/Circles – Rectangles/Squares – Polygons – Images 2 main tasks to add these elements – Create an SG annotation data set – Modify the SG procedure to use this data set
10
SG Annotation - Example data sgannodata1; infile datalines dlm='#'; length function $ 9 linecolor $ 4 shape $ 6 direction $ 3; input function x1 y1 x2 y2 height width linecolor shape direction ; datalines; rectangle # 50 # 50 #. #. # 30 # 40 # blue # # arrow # 51 # 50 # 30 # 35 #. #. # red # closed # out ; run; proc sgplot data=sashelp.class noborder sganno=sgannodata1 ; scatter x=weight y=height; run;
11
SG Annotation Macros Set of 10 macros Can be used within a DATA to simplify the process of creating annotation observations %SGARROW%SGPOLYGON %SGIMAGE%SGPOLYLINE %SGLINE%SGRECTANGLE %SGOVAL%SGTEXT %SGPOLYCONT%SGTEXTCONT
12
SG Annotation Macros data sgannodata1; infile datalines dlm='#'; length function $ 9 linecolor $ 4 shape $ 6 direction $ 3; input function x1 y1 x2 y2 height width linecolor shape direction ; datalines; rectangle # 50 # 50 #. #. # 30 # 40 # blue # # arrow # 51 # 50 # 30 # 35 #. #. # red # closed # out ; run; data sgannodata2; %sgrectangle(x1=50, y1=50, height=30, width=40, linecolor="blue"); %sgarrow(x1=51, x2=30, y2=35, linecolor="red", shape="closed", direction="out"); run; =
13
Axis break proc sgplot data=break noautolegend; highlow y=y low=zero high=x / group=y lineattrs=(thickness=3); xaxis integer offsetmin=0; yaxis min=0 max=4; run; proc sgplot data=break noautolegend; highlow y=y low=zero high=x / group=y lineattrs=(thickness=3); xaxis ranges=(1-3.5 9.75-11) integer offsetmin=0; yaxis min=0 max=4; run; Full height break. What if you want a break in the axis only?
14
AXISBREAK macro Create graph as shown before %AXISBREAK uses an annotation polygon function to erase the full break %AxisBreak (Axis=X, low=3.5, high=9.75, dataout=anno, back=wall type=bracket); proc sgplot data=break noborder sganno=anno; scatter x=x y=y; xaxis ranges=(1 - 3.5 9.75 - 11) integer; yaxis min=0 max=4; run;
15
TEMPLATE MODIFICATION MACROS
16
Modifying Style Templates - Recap 1. Obtain the source code proc template; source styles.default; run; 2. Modify the code proc template; define style MyListingStyle; parent=styles.listing; make desired changes in code end; run; 3. Generate the plot ods listing style=mylistingstyle; SGPLOT Statements
17
Modifying Graph Templates - Recap 1. Obtain the source code proc template; source Stat.Lifetest.Graphics.ProductLimitSurvival; run; 2. Modify the code proc template; define Stat.Lifetest.Graphics.ProductLimitSurvival; source Stat.Lifetest.Graphics.ProductLimitSurvival; make desired changes in code end; run; 3. Generate the plot proc lifetest data=db plots=s; statements run; 4. Revert to default template proc template; delete Stat.Lifetest.Graphics.ProductLimitSurvival; run;
18
MODSTYLE Macro Allows you to easily make changes to style templates without accessing the code %modstyle(parent=listing, name=MyListing, type=CLM, NumberOfGroups=3, colors=magenta purple brown, linestyles=Solid ShortDash MediumDash); ods listing style=MyListing; proc lifetest data=sashelp.BMT plots=survival(atrisk=0 to 2500 by 500); time T * Status(0); strata Group; run;
19
MODSTYLE Macro OPTIONDESCRIPTION COLORS = color-listspecify colors for markers and lines DISPLAY = n|1 specify whether to display the generated template FILLCOLORS = color-listspecify colors for bands and fills LINESTYLES = line-style-listspecify styles for lines MARKERS = marker=listspecify marker symbol list NAME = style-namespecify name for new style you are creating NUMBEROF GROUPS = n specify the number of GraphData elements to create (default is 32) PARENT = style-namespecify the parent style TYPE = type-specification specify how to cycle through colors CLM: cycles through colors, lines and markers simultaneously LMbyC: fixes lines and markers, cycles through colors CbyLM: fixes color, cycles through lines and markers CbyLbyM: fixes color and line style, cycles through markers, increments line style, then moves to through markers. After all line styles are used, then moves to next color LbyMbyC: fixes line style and marker, cycles through colors, increments marker, then moves to through colors. After all markers are used, then moves to next line
20
MODTMPLT Macro Allows you to easily make limited changes to graph templates without accessing the code title “MY TITLE”; %modtmplt(template=Stat. Lifetest.Graphics.ProductLimitSurvival, options=replace, steps=t); proc reg data=class plots(only)=fitplot; model weigh = height; run;
21
MODTMPLT Macro OptionDescription BY=by-variable-listspecifies the list of BY variables when graphs are produced BYLIST=by-statement- list specifies the full syntax of the BY statement. You can specify a full BY statement syntax including the DESCENDING or NOTSORTED options DATA=SAS-data-setspecifies the input SAS data set when graphs are produced FILE=filenamespecifies the file in which to store the original templates OPTIONS=options specifies one or more of the following options: LOGdisplays a note in the SAS log when each BY group has finished. FIRSTadds the ENTRYTITLE or ENTRYFOOTNOTE statements as the first titles or footnotes. REPLACE replaces the unconditionally added entry titles and entry footnotes in the templates (those that are not part of IF or ELSE statements) with the system titles and footnotes SOURCEdisplays the generated source code TITLESdisplays the system titles and footnotes with the graphs STATEMENT=entry- statement-fragment specifies the statement that contains the BY line that gets added to the template along with any statement options (e.g Statement=EntryFootNote halign=left TextAttrs=GraphValueTex) STEPS=steps specifies the macro steps to run Tmodify template Ggenerate graph Ddelete template STMTOPTS1=n - STMTOPTS10=n allows to add or replace options in selected statements (e.g. stmtopts1=. add discretelegend autoalign=(topleft)) TEMPLATE=SAS- template specifies the name of the template to modify. TITLES=SAS-data-setspecifies a data set that contains titles or footnotes or both TITLEOPTS=entry- statement-options specifies the options for system titles and footnotes (e.g. HALIGN= and TEXTATTRS= )
22
GRAPHICAL MACROS
23
CompactMatrixMacro (Author: Sanjay Matange) proc sgscatter data=safety; matrix asat alat alkph biltot; run; %CompactMatrixMacro(data=safety, var1=asat, var2=alat, var3=alkph, var4=biltot);
24
NEWSURV Macro (Author: Jeff Meyers)
25
NEWSURV Macro Call %newsurv(data=sashelp.bmt, time=T, cens=status, cen_vl=0, class=group, classref=ALL, /*class ref for HR*/ classdesc=Group, /*label for class var*/ classvalalign=left, /*alignment for class values*/ risklabellocation=above, risklocation=bottom, /*location of n at risk table*/ risklist=0 to 7 by 0.5, /*time values for n at risk*/ timelist=1 to 2 by 1, /*time values for which to display KM estimates */ timedx=Years, /*label to desribe time units on table*/ xmin=0, xmax=7, xincrement=0.5, xdivisor=365.25, /*manage x axis*/ ytype=ppt, /*y axis in percentage (pct) or proportion*/ xlabel=Time (Years), ylabel=Proportion Alive and Disease-Free, /*axis labels*/ symbolsize=6pt, linesize=2pt, color=BLACK BLUE RED, /*manage style */ title=General Example of a Kaplan Meier Plot Showing Multiple Options with SASHELP.BMT Dataset, width=9in, height=6in, gpath=&BaseDir,plotname=Ex7, plottype=png);
26
NEWSURV Macro Examples
28
NEWSURV Macro Also produces a table report of the information You can control what columns appear You can include more than 1 mode in the call/table You can export directly to RTF, PDF OR HTML
29
FORESTPLOT Macro (Author: Jeff Meyers)
30
FORESTPLOT Macro %forestplot (DATA=neuralgia, METHOD=LOGISTIC, /*logistic, phreg, km or binomial*/ LOGPROC=logistic, /*calculate ORs with logistic or genmod*/ EVENTCOV=pain, EVENT=Yes, /*event variable and event level*/ CATCOV=sex, CONTCOV=age, /*categorical and continuous vlists*/ MDISPLAY=cat1 cont1, /*which variables to displayed and their order*/ CATDISPLAY=2, /*display for cat vars, see documentation for options*/ XAXISTYPE=log, /*display log*/ LABEL=Odds Ratios, /*x-axis label*/ BY=TREATMENT, /*by var*/ T3PVAL=wald, /*type of test for type 3 p-value*/ DISPLAY=ev_t est_range pval, /*stats to display*/ CWEIGHTS=0.2 0.4 0.4, /*amount of plot space for labels graph & stats*/ gpath=&BaseDir,plotname=Ex8d,plottype=png);
31
FORESTPLOT Macro %forestplot(DATA=sashelp.bmt, METHOD=KM, NMODELS=2, TIME=t, CENS=status, TIMEPOINT=1000, LABEL=Event-free Rate, TIMEDX=Days, CWEIGHTS=0.25 0.35 0.4, HEIGHT=6in, BY=|group, TDISPLAY=3, MTITLE=All Patients|, BYLABEL=|By Disease Group, SUBHEADER=1000 Day DFS, DISPLAY=EV_T est_range pval, MODPVAL=|logrank, SYMBOL=diamondfilled|circlefilled, SYMBOLSIZE=20pt|10pt, ERRORBARS=0|1, gpath=&BaseDir,plotname=Ex8l,plottype=png);
32
EULER_MACRO %Euler_Macro ( n1=30, /*n for set 1 (n1 + ni = N1)*/ n2=20, /*n for set 2*/ ni=10, /*n for intersection only*/ skin=gloss);
33
VENN Macro %venn(data = work.data, venn_diagram=4, /*# of sets to plot*/ cutoff=<0.3, /*cutoff for quantitative vars. Plots counts satisfying these statement*/ out_location=&BaseDir, outputfilename=Ex10a);
34
GLTPIECHARTMACRO %GTLPieChartMacro(data=sashelp.prdsale, category=product, /*group var*/ response=actual, /*var that has value for area of slice. This is optional, if not included it would plot freq or pct of category var*/ dataskin=gloss, title=Actual Sales by Product, footnote=Data Set: SAShelp.prdsale, footnotefontsize=6);
35
WHERE TO FIND THE MACROS
36
MacroWhere to obtain it Color utility macros SAS autocall macros SGAnnotation macros %MODSTYLE %MODTMPLT %AXISBREAK http://blogs.sas.com/content/graphicallysp eaking/2014/11/18/axis-break-appearance- macro/ %COMPACTMATRIXMACRO http://blogs.sas.com/content/graphicallysp eaking/2012/08/19/compact-scatter-plot- matrix/ %ORTHO3D_MACRO http://blogs.sas.com/content/graphicallysp eaking/2015/03/10/a-3d-scatter-plot- macro/
37
MacroWhere to obtain it %NEWSURV http://www.sascommunity.org/wiki/Kaplan- Meier_Survival_Plotting_Macro_%25NEWS URV %FORESTPLOT http://www.sascommunity.org/wiki/Forest_Pl otting_Analysis_Macro_%25FORESTPLOT %EULER_MACRO http://blogs.sas.com/content/graphicallyspea king/2014/06/29/proportional-euler-diagram/ %VENN http://support.sas.com/resources/papers/pro ceedings13/243-2013.pdf %GTLPIECHARTMACRO http://blogs.sas.com/content/graphicallyspea king/2012/08/26/how-about-some-pie/
38
QUESTIONS??
39
Coming up Step-by-step examples of common graphs – Please email me with suggestions! ODS Graphics Designer and Editor
40
THANKS
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.