SAS Graphical Macros February 17, 2016 Rocio Lopez.

Slides:



Advertisements
Similar presentations
Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Advertisements

Taking the Leap - Using ODS Statistical Graphics for Data Visualization Wei Cheng, Isis Pharmaceuticals, Inc.
Prepared by : Mahmoud A. Abu Hashish  Used to organize and analyze information  Made up of columns and rows  Columns and rows intersect.
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
® Microsoft Office 2010 Word Tutorial 3 Creating a Multiple-Page Report.
Excel Charts – Basic Skills Creating Charts in Excel.
Introduction to SPSS Allen Risley Academic Technology Services, CSUSM
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
What is New in SAS 9.2? Graphics and More. A Brief History of SAS Graphics 6.x 7.x = had the Output Delivery System (ODS) but it was not widely available.
GRAPHICAL DESCRIPTIVE STATISTICS FOR QUALITATIVE, TIME SERIES AND RELATIONAL DATA.
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a Message.
1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a Message Robert Grauer and Maryann Barber Exploring.
Basic And Advanced SAS Programming
1 Computing for Todays Lecture 10 Yumei Huo Fall 2006.
XP New Perspectives on Microsoft Office Excel 2003 Tutorial 4 1 Microsoft Office Excel 2003 Tutorial 4 – Working With Charts and Graphics.
1 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
11 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Bay Area SUG June SAS ® 9.2 Implications for Biotech SAS ® 9.2 Implications for Biotech Bay Area SAS User’s Group June 7 th 2010 Sarmad Pirzada,
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
Computers Are Your Future © 2006 Prentice-Hall, Inc.
McGraw-Hill Career Education© 2008 by the McGraw-Hill Companies, Inc. All Rights Reserved. 2-1 Office PowerPoint 2007 Lab 2 Modifying and Refining a Presentation.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
ODS Statistical Graphics in SAS 9.2 January 17, 2010.
A Picture Is Worth A Thousand Words. DAY 7: EXCEL CHAPTER 4 Tazin Afrin September 10,
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
01/20151 EPI 5344: Survival Analysis in Epidemiology SAS code and output February 24, 2015 Dr. N. Birkett, School of Epidemiology, Public Health & Preventive.
Jorge Cornejal Carlin Baez Edisson Garcia. How to Use LAYERs Illustrator's layers allow you to simplify your work. With layers, you can modify, edit,
Introduction to SAS/Graph 9.2 Ken Barz Colorado Prevention Center 22Oct2009 Ken Barz Colorado Prevention Center.
Using the new Version 8 Template Procedure for Complete Control of SAS Output Style and Format David Ghan Technical Training Specialist SAS, Canada.
Advanced Stata Workshop FHSS Research Support Center.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
CREATING CHARTS By: Dr. Ennis - Cole OBJECTIVES b Identify the elements of an Excel chart b Identify the type of chart represents your data most effectively.
SAS ODS (Output Delivery System) Donald Miller 812 Oswald Tower ;
Return to Outline Copyright © 2011 by Maribeth H. Price 3-1 Labeling and annotation.
Lecture 3 Topic - Descriptive Procedures Programs 3-4 LSB 4:1-4.4; 4:9:4:11; 8:1-8:5; 5:1-5.2.
Who Wants to be a Millionaire? LIFELINES 1.50/50 2.Poll the audience 3.Ask Another Student.
Effective SAS greplay’ing and how to avoid stretching By David Mottershead Senior Programmer, Quanticate.
Mr. Magdi Morsi Statistician Department of Research and Studies, MOH
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming SAS Graphics SAS has two main facilities for producing graphics: 1.ODS.
Lesson 8 - Topics Creating SAS datasets from procedures Using ODS and data steps to make reports Using PROC RANK Programs in course notes LSB 4:11;5:3.
An Introduction Katherine Nicholas & Liqiong Fan.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
Customize SAS Output Using ODS Joan Dong. The Output Delivery System (ODS) gives you greater flexibility in generating, storing, and reproducing SAS procedure.
Multiple Imputation using SAS Don Miller 812 Oswald Tower
#pharmasug About OMICS Group OMICS Group is an amalgamation of Open Access Publications and worldwide international science conferences and events. Established.
SAS ® is a very powerful tool when producing Graphics. A single graphical data step can easily create a Kaplan Meier Plot, but there is no single graphical.
Statistical Fundamentals: Using Microsoft Excel for Univariate and Bivariate Analysis Alfred P. Rovai Charts Overview PowerPoint Prepared by Alfred P.
Introduction to SAS ODS Graphics September 16, 2015 Rocio Lopez.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Thinking about Graphs The Grammar of Graphics and SAS.
SOC 305, Prof. Robert Martin Southeastern Louisiana University.
Computer Graphics: Achromatic and Coloured Light.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
03/20161 EPI 5344: Survival Analysis in Epidemiology Testing the Proportional Hazard Assumption April 5, 2016 Dr. N. Birkett, School of Epidemiology, Public.
Kaplan-Meier Survival Plotting Macro %NEWSURV Jeffrey Meyers Mayo Clinic, Rochester, Minnesota 1 BB-13.
Kaplan-Meier Survival Plotting Macro %NEWSURV Jeffrey Meyers Mayo Clinic, Rochester, MN.
Forest Plotting Analysis Macro %FORESTPLOT (Paper 3419)
ODS Graphics By Example March 16, 2016 Rocio Lopez.
ODS Graphics: Modifying Style Attributes October 21, 2015 Rocio Lopez.
Chapter 8: ODS Graphics ODS graphics were not available prior to SAS 9.2 They have been implemented across a wide range of procedures Functionality isn’t.
Getting Started with the SGPLOT Procedure: A Hands-On Workshop About the Presenter 1/14/2019 Josh Horstman is an independent statistical programming consultant.
Clinical Graphs using SAS®
Presentation transcript:

SAS Graphical Macros February 17, 2016 Rocio Lopez

Overview Color utility macros Annotation macros Template modification macros Graphical macros Where to find each macro

COLOR UTILITY MACROS

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

%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

%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;

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 xcn1qchqznw88m6e.htm

ANNOTATION MACROS

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

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;

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

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; =

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=( ) integer offsetmin=0; yaxis min=0 max=4; run; Full height break. What if you want a break in the axis only?

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=( ) integer; yaxis min=0 max=4; run;

TEMPLATE MODIFICATION MACROS

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

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;

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;

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

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;

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= )

GRAPHICAL MACROS

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);

NEWSURV Macro (Author: Jeff Meyers)

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);

NEWSURV Macro Examples

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

FORESTPLOT Macro (Author: Jeff Meyers)

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= , /*amount of plot space for labels graph & stats*/ gpath=&BaseDir,plotname=Ex8d,plottype=png);

FORESTPLOT Macro %forestplot(DATA=sashelp.bmt, METHOD=KM, NMODELS=2, TIME=t, CENS=status, TIMEPOINT=1000, LABEL=Event-free Rate, TIMEDX=Days, CWEIGHTS= , 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);

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);

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);

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);

WHERE TO FIND THE MACROS

MacroWhere to obtain it Color utility macros SAS autocall macros SGAnnotation macros %MODSTYLE %MODTMPLT %AXISBREAK eaking/2014/11/18/axis-break-appearance- macro/ %COMPACTMATRIXMACRO eaking/2012/08/19/compact-scatter-plot- matrix/ %ORTHO3D_MACRO eaking/2015/03/10/a-3d-scatter-plot- macro/

MacroWhere to obtain it %NEWSURV Meier_Survival_Plotting_Macro_%25NEWS URV %FORESTPLOT otting_Analysis_Macro_%25FORESTPLOT %EULER_MACRO king/2014/06/29/proportional-euler-diagram/ %VENN ceedings13/ pdf %GTLPIECHARTMACRO king/2012/08/26/how-about-some-pie/

QUESTIONS??

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

THANKS