Color Utility Macros Overview and Usage

sas graphical macros n.w
1 / 40
Embed
Share

Explore a comprehensive guide on color utility macros within SAS, including managing color names, creating RGB color names, and utilizing different color-naming schemes. Learn how to initiate macros, get help on specific macros, and run them within SGPLOT, SGPanel, or GTL. Discover other available color utility macros and annotation macros for adding various elements to SAS graphics.

  • SAS Macros
  • Color Utility
  • RGB Color Names
  • Color-Naming Schemes
  • Annotation Macros

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  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 Macro Description Creates an RGB color name from numeric CMY components Creates an CMYK color name from numeric CMYK components Creates a HLS color name from a color-naming scheme (CLS) color name Creates an HLS color name from numeric HLS component values Creates an HLS color name from numeric HSV components Creates and RGB color name from an HLS color name Creates and HLS color name from an RGB color name %CMY(cyan, magenta, yellow); %CMYKCMY(cyan, magenta, yellow, black); %CNS(cns-color-name); %HLS(hue, lightness, saturation); %HSV(hue, saturation, value); %HLS2RGB(hls-color-name); %RGB2HLS(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 %SGIMAGE %SGLINE %SGOVAL %SGPOLYCONT %SGPOLYGON %SGPOLYLINE %SGRECTANGLE %SGTEXT %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 proc template; source styles.default; run; 1. Obtain the source code proc template; define style MyListingStyle; parent=styles.listing; make desired changes in code end; run; 2. Modify the code ods listing style=mylistingstyle; SGPLOT Statements 3. Generate the plot

  17. Modifying Graph Templates - Recap proc template; source Stat.Lifetest.Graphics.ProductLimitSurvival; run; 1. Obtain the source code proc template; define Stat.Lifetest.Graphics.ProductLimitSurvival; source Stat.Lifetest.Graphics.ProductLimitSurvival; make desired changes in code end; run; 2. Modify the code proc lifetest data=db plots=s; statements run; 3. Generate the plot proc template; delete Stat.Lifetest.Graphics.ProductLimitSurvival; run; 4. Revert to default template

  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 OPTION COLORS = color-list DESCRIPTION specify colors for markers and lines specify whether to display the generated template specify colors for bands and fills specify styles for lines specify marker symbol list specify name for new style you are creating specify the number of GraphData elements to create (default is 32) specify the parent style 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 DISPLAY = n|1 FILLCOLORS = color-list LINESTYLES = line-style-list MARKERS = marker=list NAME = style-name NUMBEROF GROUPS = n PARENT = style-name TYPE = type-specification

  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 Option BY=by-variable-list BYLIST=by-statement- list DATA=SAS-data-set FILE=filename Description specifies the list of BY variables when graphs are produced specifies the full syntax of the BY statement. You can specify a full BY statement syntax including the DESCENDING or NOTSORTED options specifies the input SAS data set when graphs are produced specifies the file in which to store the original templates specifies one or more of the following options: LOG displays a note in the SAS log when each BY group has finished. FIRST adds the ENTRYTITLE or ENTRYFOOTNOTE statements as the first titles or footnotes. 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 SOURCE displays the generated source code TITLES displays the system titles and footnotes with the graphs 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) specifies the macro steps to run T modify template G generate graph D delete template allows to add or replace options in selected statements (e.g. stmtopts1=. add discretelegend autoalign=(topleft)) OPTIONS=options REPLACE STATEMENT=entry- statement-fragment STEPS=steps STMTOPTS1=n - STMTOPTS10=n TEMPLATE=SAS- template TITLES=SAS-data-set TITLEOPTS=entry- statement-options specifies the name of the template to modify. specifies a data set that contains titles or footnotes or both 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

  27. 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. Macro Color utility macros SGAnnotation macros %MODSTYLE %MODTMPLT Where to obtain it SAS autocall macros http://blogs.sas.com/content/graphicallysp eaking/2014/11/18/axis-break-appearance- macro/ http://blogs.sas.com/content/graphicallysp eaking/2012/08/19/compact-scatter-plot- matrix/ http://blogs.sas.com/content/graphicallysp eaking/2015/03/10/a-3d-scatter-plot- macro/ %AXISBREAK %COMPACTMATRIXMACRO %ORTHO3D_MACRO

  37. Macro Where to obtain it http://www.sascommunity.org/wiki/Kaplan- Meier_Survival_Plotting_Macro_%25NEWS URV http://www.sascommunity.org/wiki/Forest_Pl otting_Analysis_Macro_%25FORESTPLOT http://blogs.sas.com/content/graphicallyspea king/2014/06/29/proportional-euler-diagram/ http://support.sas.com/resources/papers/pro ceedings13/243-2013.pdf http://blogs.sas.com/content/graphicallyspea king/2012/08/26/how-about-some-pie/ %NEWSURV %FORESTPLOT %EULER_MACRO %VENN %GTLPIECHARTMACRO

  38. QUESTIONS??

  39. Coming up Step-by-step examples of common graphs Please email me with suggestions! ODS Graphics Designer and Editor

  40. THANKS

More Related Content