Lesson 12 More SGPLOT examples Exporting data Macro variables Table Generation - PROC TABULATE Miscellaneous Topics.

Slides:



Advertisements
Similar presentations
The SAS ® System Additional Information on Statistical Analysis Programming.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Outlook Contacts Export Guideline Powered by DonorCommunity TM DonorCommunity eLearning Series v1.2, September 2012 Outlook Contacts Export Guideline Outlook.
1 SAS Formats and SAS Macro Language HRP223 – 2011 November 9 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
Basic And Advanced SAS Programming
Continuous Moderator Variables
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
How to Build Tabular Dashboards Using Proc Report
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Collection and Analysis of Data CPH 608 Spring 2015.
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks.
SAS PROC REPORT PROC TABULATE
Miscellaneous Excel Combining Excel and Access. – Importing, exporting and linking Parsing and manipulating data. 1.
My ODS: Real-World Uses of Modifying Table Templates Steve James Centers for Disease Control and Prevention Atlanta, Ga.
Lesson 5 - Topics Formatting Output Working with Dates Reading: LSB:3:8-9; 4:1,5-7; 5:1-4.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Macro Overview Mihaela Simion. Macro Facility Overview Definition : The SAS Macro Facility is a tool within base SAS software that contains the essential.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to SAS Essentials Mastering SAS for Data Analytics
Advanced Stata Workshop FHSS Research Support Center.
March 28, 30 Return exam Analyses of covariance 2-way ANOVA Analyses of binary outcomes.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
How to start using SAS Tina Tian. The topics An overview of the SAS system Reading raw data/ create SAS data set Combining SAS data sets & Match merging.
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.
Lesson 4 - Topics Creating new variables in the data step SAS Functions.
MASUG September 15, Agenda  Guest Introductions  John Boling – SAS inSchool  Tim Garton – Health Forecasts  Announcements  Tips & Tricks 
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.
SAS Basics. Windows Program Editor Write/edit all your statement here.
Lecture 4 Ways to get data into SAS Some practice programming
Patrick Thornton SRI International.  Example of a Multiple Response Item ◦ Variable coding and example data  A Cross Tabulation using Proc REPORT 
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
BMTRY 789 Lecture9: Proc Tabulate Readings – Chapter 11 & Selected SUGI Reading Lab Problems , 11.2 Homework Due Next Week– HW6.
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.
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.
Lecture 3 Topic - Descriptive Procedures
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
Introduction to Graphing in SAS
Today: Feb 28 Reading Data from existing SAS dataset One-way ANOVA
Lesson 4 Descriptive Procedures
Lesson 2 Topic - Reading raw data into SAS
Microsoft Excel Basic Skills
Lesson 12 Topics Macro example Exporting data Character Functions
Lesson 13 More SGPLOT examples MAP Plotting Questions.
Lesson 9 - Topics Restructuring datasets LSB: 6:14
Lesson 8 - Topics Creating SAS datasets from procedures
Chapter 7: Macros in SAS Macros provide for more flexible programming in SAS Macros make SAS more “object-oriented”, like R Not a strong suit of text ©
Lesson 11 - Topics Statistical procedures: PROC LOGIST, REG
Lesson 7 - Topics Reading SAS data sets
Working With Dates: Dates Come in Many Ways
Demonstrating the Linear Model
Complete Case Macro.
Lecture 2 Topics - Descriptive Procedures
Working With Dates: Dates Come in Many Ways
Never Cut and Paste Again
Purpose Real life scenario: I have a set of reports to refresh every month but data is only available at any day during Day 3 – 5 at beginning of each.
Appending and Concatenating Files
Set Axis macro.
Lecture 2 Topics - Descriptive Procedures
Presentation transcript:

Lesson 12 More SGPLOT examples Exporting data Macro variables Table Generation - PROC TABULATE Miscellaneous Topics

SCATTER vs SERIES vs REG vs STEP Obs trt month cd Want to plot mean CD4 levels over time for each of two groups.

* Scatter Plot for 2 group; proc sgplot; xaxis label = 'Months After Start of Therapy' values=(0 to 36 by 6); yaxis label = 'Mean CD4 Level'; title 'Mean CD4 After Start of Therapy by Treatment Type'; scatter x=month y=cd4/group=trt ; format trt trtF.; label trt = 'Treatment Group'; run; SCATTER vs SERIES vs REG vs STEP

* Series plot connects the points, marker option needed to plot symbols at each visit; proc sgplot; series x=month y=cd4/group=trt markers ; run;

* Regression plot does scatter plot and adds regression line; proc sgplot; reg x=month y=cd4/group=trt ; run;

* Step plot connects points with a step function; proc sgplot; step x=month y=cd4/group=trt ; run;

* Exporting Data; LIBNAME mylib ‘C:\SAS_Files’; DATA temp; SET mylib.sescore; KEEP ptid clinic randdate group educ wt12 sbp12 sescr12; RUN; * Export data to a comma delimited file; PROC EXPORT DATA=temp OUTFILE = 'C:\SAS_Files\se.csv' DBMS = csv REPLACE;

Contents of file 'se.csv' ptid,clinic,randdate,group,educ,wt12,sbp12,sescr12 A00083,A,02/05/1987,2,7,125,113,1.05 A00301,A,02/17/1987,6,9,,,1.15 A00312,A,04/08/1987,3,4,131,113,1.15 This data can easily be put into excel by clicking on the file and then saving the file as a worksheet. *export to excel directly; PROC EXPORT DATA=temp OUTFILE = 'C:\SAS_Files\se.xls' DBMS = excel ; REPLACE;

Moving a SAS Dataset to another computer Transfer SAS dataset directly - Easy and works on most systems - Can send as attachment Use PROC CPORT and PROC CIMPORT Works on all systems but requires you to create an xport (.xpt) file. Can transfer multiple datasets in one file.

Creating a SAS Export File *Run this on the your computer ; LIBNAME mylib ‘C:\SAS_Files'; FILENAME tranfile ‘C:\SAS_Files\classdata.xpt'; PROC CPORT LIB=mylib FILE=tranfile; SELECT sescore tomhsp; RUN; * Run this on the other computer ; FILENAME tranfile 'C:\My SAS Datasets\classdata.xpt'; PROC CIMPORT LIB=work FILE=tranfile; PROC CONTENTS VARNUM DATA=sescore; PROC CONTENTS VARNUM DATA=tomhsp; RUN;

TABLE GENERATION (dbp12 sbp12)*(N MEAN*f=8.1) GROUPALLGROUPALL

PROC TABULATE DATA=class.tomhsp FORMAT=8.0; CLASS group; VAR sbp12 dbp12; TABLES group ALL='Total', (dbp12 sbp12)*(N MEAN*f=8.1)/RTS=20; LABEL dbp12 = 'Diastolic BP'; LABEL sbp12 = 'Systolic BP'; LABEL group = 'RX Group'; FORMAT group fgroup.; TITLE 'Average Blood Pressure at 12-Months'; RUN; Same as PROC MEANS

Closer Look At TABLES Statement TABLES group ALL='Total', (dbp12 sbp12)*(N MEAN*f=8.1)/RTS=20; Statement before comma indicates row information to display Statement after comma indicates column information to display A * indicates to crosstabulate data A space indicates to concatenate data Words: For each group and the total display the N and mean of diastolic and systolic BP

(sex=' ')*(N ROWPCTN*f=10.1) CLINICALLCLINICALL

PROC TABULATE DATA=class.tomhsp FORMAT=8.; CLASS clinic sex; TABLE (clinic ALL='Total'), (sex=' ')*(N ROWPCTN*f=10.1)/RTS=15; FORMAT sex sex. clinic $clinic.; LABEL clinic = 'Clinical Center'; KEYLABEL ROWPCTN = 'Percent'; TITLE 'N and Percent Men and Women Enrolled by Center'; RUN; ODS HTML FILE = ‘mytable.html’;

Macro Variables and Use LIBNAME t ‘C:\SAS_Files'; %let nut = kcalbl dcholbl calcbl sodbl; %let ilist = income educ; %let options = N MEAN STDDEV; DATA temp; SET t.tomhsp (KEEP=ptid clinic &nut &ilist); PROC MEANS DATA=temp &options; VAR &nut &ilist; TITLE "PROC Means results for variables &nut and &ilist"; RUN; * Makes it easy to modify code;

Macro Variables Defined using %LET statement Referenced by using &macrovarname SAS substitutes the value of macrovarname when it encounters &macrovarname Useful for making a program easy to modify %let macrovarname = characters ;

Simple Macro to Shorten Code %macro change(v); dbpdif&v = dbp&v - dbpbl; sbpdif&v = sbp&v - sbpbl; choldif&v = chol&v - cholbl; glucdif&v = gluc&v - glucbl; %mend change; data temp; set temp; %change(12); %change(24); %change(36); run; Suppose I want to compute the change in 4 variables at 3 time points. Can use macro to help you. Variables: Dbp12,24,36 and dbpbl Sbp12,24,36 and sbpbl Chol12,24,36 and cholbl Gluc12,24,36 and glucbl

Simple Macro to Shorten Code %macro change(v); 36 %change(12); MPRINT(CHANGE): dbpdif12 = dbp12 - dbpbl; MPRINT(CHANGE): sbpdif12 = sbp12 - sbpbl; MPRINT(CHANGE): choldif12 = chol12 - cholbl; MPRINT(CHANGE): glucdif12 = gluc12 - glucbl; 36 %change(24); MPRINT(CHANGE): dbpdif24 = dbp24 - dbpbl; MPRINT(CHANGE): sbpdif24 = sbp24 - sbpbl; MPRINT(CHANGE): choldif24 = chol24 - cholbl; MPRINT(CHANGE): glucdif24 = gluc24 - glucbl; 37 %change(36); MPRINT(CHANGE): dbpdif36 = dbp36 - dbpbl; MPRINT(CHANGE): sbpdif36 = sbp36 - sbpbl; MPRINT(CHANGE): choldif36 = chol36 - cholbl; MPRINT(CHANGE): glucdif36 = gluc36 - glucbl; 38 run; SAS substitutes the value of v everywhere there is an &v