Lesson 8 - Topics Creating SAS datasets from procedures Using ODS and data steps to make reports Using PROC RANK Programs 14-15 in course notes LSB 4:11;5:3.

Slides:



Advertisements
Similar presentations
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Advertisements

16b. Accessing Data: Means in SAS ®. 1 Prerequisites Recommended modules to complete before viewing this module  1. Introduction to the NLTS2 Training.
Knowing Understanding the Basics Writing your own code part 2 SAS Lab.
SAS Programming: Working With Variables. Data Step Manipulations New variables should be created during a Data step Existing variables should be manipulated.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Quick Data Summaries in SAS Start by bringing in data –Use permanent data set for these examples Proc Tabulate –Produces summaries very quickly and easily.
Basic And Advanced SAS Programming
Introduction to SAS Lecture 2 Brian Healy.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Week 3 Topic - Descriptive Procedures Program 3 in course notes Cody & Smith (Chapter 2)
SAS PROC REPORT PROC TABULATE
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
USING SAS PROCEDURES SAS System Options OPTIONS Statement
Niraj J. Pandya, Element Technologies Inc., NJ.  Summarize all possible combinations of class level variables even if few categories are altogether missing.
Adventures in ODS: Producing Customized Reports Using Output from Multiple SAS® Procedures Stuart Long Westat, Durham,
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.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Knowing Understanding the Basics Writing your own code SAS Lab.
April 6 Logistic Regression –Estimating probability based on logistic model –Testing differences among multiple groups –Assumptions for model.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
1 Filling in the blanks with PROC FREQ Bill Klein Ryerson University.
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.
Chapter 5 Reading and Manipulating SAS ® Data Sets and Creating Detailed Reports Xiaogang Su Department of Statistics University of Central Florida.
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.
SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically.
Lesson 4 - Topics Creating new variables in the data step SAS Functions.
1 EPIB 698C Lecture 4 Raul Cruz-Cano Summer 2012.
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming Sorting, Printing, Summarizing Data Now that we can input data and do.
The Distribution of Single Variables. Two Types of Variables Continuous variables – Equal intervals of measurement – Known zero-point that is meaningful.
Lesson 12 More SGPLOT examples Exporting data Macro variables Table Generation - PROC TABULATE Miscellaneous Topics.
SAS Basics. Windows Program Editor Write/edit all your statement here.
Today: March 7 Data Transformations Rank Tests for Non-Normal data Solutions for Assignment 4.
An Introduction Katherine Nicholas & Liqiong Fan.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
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
SHRUG, F EB 2013: N ETWORKING EXERCISE Many Ways to Solve a SAS Problem.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
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
The Urban Institute - SAS Training6/9/20161 SAS Training This SAS Training Course was designed to introduce users at The Urban Institute to SAS programming.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
Lesson 10 - Topics SAS Procedures for Standard Statistical Tests and Analyses Programs 19 and 20 LSB 8:16-17.
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.
Today: Feb 28 Reading Data from existing SAS dataset One-way ANOVA
Applied Business Forecasting and Regression Analysis
Lesson 4 Descriptive Procedures
Lesson 3 Overview Descriptive Procedures Controlling SAS Output
Lecture 2 Topics - Descriptive Procedures
Lesson 9 - Topics Restructuring datasets LSB: 6:14
Lesson 8 - Topics Creating SAS datasets from procedures
Lesson 11 - Topics Statistical procedures: PROC LOGIST, REG
Quick Data Summaries in SAS
Working With Dates: Dates Come in Many Ways
Lecture 2 Topics - Descriptive Procedures
Working With Dates: Dates Come in Many Ways
Producing Descriptive Statistics
Lecture 2 Topics - Descriptive Procedures
Presentation transcript:

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

Making SAS Datasets From Procedures Output from SAS PROCs can be put into SAS datasets: 1.To do further processing of the information from the output 2.To reformat output to make a report 3.To restructure original SAS dataset or create new variables

Ways to Put Output into SAS Datasets Using OUTPUT statement available from many procedures Using ODS OUTPUT statement – any output table can be put into a SAS dataset

Report We Want to Generate Quartiles of Weight by Gender and Center sex clinic N P25 P50 P75 Male A Male B Male C Male D Female A Female B Female C Female D

Program 14 LIBNAME class ‘C:\SAS_Files'; * Will use SAS dataset version of TOMHS data; DATA wt; SET class.tomhsp (KEEP=ptid age sex clinic wtbl wt12 ); wtchg = wt12 - wtbl; RUN; PROC FORMAT; VALUE sexF 1 = ‘Male’ 2=‘Female’; RUN;

Create report by sex and clinic of univariate info; PROC SORT DATA = wt; BY sex clinic; PROC UNIVARIATE DATA = wt NOPRINT; BY sex clinic; VAR wt12 ; OUTPUT OUT=univinfo N = n Q1 = p25 MEDIAN = p50 Q3 = P75 ; Dataset univinfo will have one observation for each combination of sex and clinic. Statistic name = variable name Name of new dataset

PROC PRINT DATA = univinfo; FORMAT sex sexF.; RUN; Obs sex clinic n p75 p50 p25 1 Male A Male B Male C Male D Female A Female B Female C Female D

PROC PRINT DATA = univinfo NOOBS; VAR sex clinic n p25 p50 p75; FORMAT p25 p50 p ; TITLE 'Quartiles of Weight by Gender/Center'; RUN; Quartiles of Weight by Gender/Center sex clinic N P25 P50 P75 Male A Male B Male C Male D Female A Female B Female C Female D

* Output quantile table to a dataset; ODS OUTPUT quantiles = qwt; PROC UNIVARIATE DATA = wt ; VAR wtbl wt12 ; RUN; ODS OUTPUT CLOSE ; PROC PRINT DATA=qwt; RUN; Using ODS to Send Output to a SAS Dataset Syntax: ODS OUTPUT output-table = new-data-set;

Obs Varname Quantile Estimate 1 wtbl100% Max wtbl99% wtbl95% wtbl90% wtbl75% Q wtbl50% Median wtbl25% Q wtbl10% wtbl5% wtbl1% wtbl0% Min wt12100% Max wt1299% wt1295% wt1290% wt1275% Q wt1250% Median wt1225% Q wt1210% wt125% wt121% wt120% Min Display of Output Dataset Would like to put side-by-side

DATA wtbl wt12 ; SET qwt; if varname = 'wtbl' then output wtbl; else if varname = 'wt12' then output wt12; RUN; PROC DATASETS ; MODIFY wtbl; RENAME estimate = wtbl; MODIFY wt12; RENAME estimate = wt12; RUN; DATA all; MERGE wtbl wt12; DROP varname; RUN; PROC PRINT; PROC DATASETS used for changing variable names Separate the data into 2 datasets Put 2 datasets side-by-side

Obs Quantile wtbl wt % Max % % % % Q % Median % Q % % % % Min

ODS OUTPUT ParameterEstimates (persist=proc) = betas; PROC REG DATA=WT; MODEL dbpchg = wtchg age sex; RUN; PROC REG data=wt; MODEL sbpchg = wtchg age sex; RUN; ODS OUTPUT CLOSE; PROC PRINT DATA=betas; RUN;

Obs Dependent Variable Estimate StdErr tValue Probt 1 dbpchg Intercept dbpchg wtchg dbpchg age dbpchg sex sbpchg Intercept sbpchg wtchg sbpchg age sbpchg sex Display of Output Dataset - Report

PROC PRINT; VAR variable estimate stderr tvalue probt; BY dependent NOTSORTED; FORMAT estimate 7.3 stderr 7.3 probt pvalue5.2 ; Dependent=dbpchg Obs Variable Estimate StdErr tValue Probt 1 Intercept wtchg age sex Dependent=sbpchg Obs Variable Estimate StdErr tValue Probt 5 Intercept wtchg age sex Display of Output Dataset Using BY Statement

PROC RANK Used to divide observations into equal size categories based on values of a variable Creates a new variable containing the categories New variable is added to the dataset or to a new dataset Example: Divide weight change into 5 equal categories (Quinitiles)

PROC RANK SYNTAX PROC RANK DATA = dataset OUT = outdataset GROUPS = # of categories VAR varname; RANKS newvarname; Most of the time you can set OUT to be the same dataset specified in DATA. PROC RANK writes no output

PROGRAM 15 LIBNAME class ‘C:\SAS_Files'; DATA wtchol; SET class.tomhsp (KEEP=ptid clinic sex wtbl wt12 cholbl chol12); wtchg = wt12 - wtbl; cholchg = chol12 - cholbl; RUN; *This PROC will add a new variable to dataset which is the tertile of weight change. The new variable will be 0,1,or 2; PROC RANK DATA = wtchol GROUPS=3 OUT = wtchol; VAR wtchg; RANKS twtchg; Name of new variable

PARTIAL LOG 8 DATA wtchol; 9 SET class.tomhsp (KEEP=ptid clinic sex wtbl wt12 cholbl chol12); 10 wtchg = wt12 - wtbl; 11 cholchg = chol12 - cholbl; 12 RUN; NOTE: There were 100 observations read from the data set CLASS.TOMHSP. NOTE: The data set WORK.WTCHOL has 100 observations and 9 variables. PROC RANK DATA = wtchol GROUPS=3 OUT = wtchol; 20 VAR wtchg; RANKS twtchg; 21 RUN; NOTE: The data set WORK.WTCHOL has 100 observations and 10 variables.

PROC FREQ DATA = wtchol; TABLES twtchg; RUN; OUTPUT: Rank for Variable wtchg Cumulative Cumulative twtchg Frequency Percent Frequency Percent ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Frequency Missing = 8

PROC PRINT DATA = wtchol (obs=20); VAR ptid wtchg twtchg; TITLE 'Partial Listing of Datset wtchol with new variable added'; RUN; Partial Listing of Datset wtchol with new variable added Obs PTID wtchg twtchg 1 A A A A A A A A A A

PROC MEANS N MEAN MIN MAX MAXDEC=2; VAR cholchg wtchg; CLASS twtchg; TITLE 'Mean Cholesterol Change by Tertile of Weight Change'; RUN;

Mean Cholesterol Change by Tertile of Weight Change The MEANS Procedure Rank for Variable N wtchg Obs Variable N Mean Minimum Maximum cholchg wtchg cholchg wtchg cholchg wtchg Could graph this data in an x-y plot (3 points) Cutpoints for tertiles