Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.

Slides:



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

Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
Creating a Compact Columnar Output with PROC REPORT Walter R. Young Principal Clinical Programmer Analyst Wyeth.
Introduction to C Programming
1 Creating and Tweaking Data HRP223 – 2010 October 24, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Introduction to SAS Essentials Mastering SAS for Data Analytics
SAS PROC REPORT PROC TABULATE
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
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
Introduction to SAS Essentials Mastering SAS for Data Analytics
1 Experimental Statistics - week 2 Review: 2-sample t-tests paired t-tests Thursday: Meet in 15 Clements!! Bring Cody and Smith book.
Quantify the Example Data First, code and quantify the data (assign column locations & variable names) Use the sample data to create a data set from the.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to SAS Essentials Mastering SAS for Data Analytics
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Priya Ramaswami Janssen R&D US. Advantages of PROC REPORT -Very powerful -Perform lists, subsets, statistics, computations, formatting within one procedure.
Chapter 5 Reading and Manipulating SAS ® Data Sets and Creating Detailed Reports Xiaogang Su Department of Statistics University of Central Florida.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
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.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
Applied Business Forecasting and Regression Analysis
Chapter 3: Working With Your Data
Instructor: Raul Cruz-Cano
Tamara Arenovich Tony Panzarella
Chapter 4: Sorting, Printing, Summarizing
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
Producing Descriptive Statistics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1

Chapter 5 Preparing to Use SAS Procedures SAS ESSENTIALS -- Elliott & Woodward2

LEARNING OBJECTIVES SAS ESSENTIALS -- Elliott & Woodward3  To be able to use SAS® Support Statements  To be able to use TITLE and FOOTNOTE  To be able to include comments in your code  To be able to use RUN and QUIT correctly  To understand SAS PROC statement syntax  To be able to use VAR statements  To be able to use BY statements  To be able to use ID statements  To be able to use LABEL statements in a SAS procedure  To be able to use WHERE statements  To be able to use PROC PRINT  Going Deeper: To be able to use common System Options  Going Deeper: To be able to split column titles

5.1 UNDERSTANDING SAS SUPPORT STATEMENTS Using TITLE and FOOTNOTES Statements  Specify up to 10 titles or footnotes TITLE ‘title text’; FOOTNOTE ‘footnote text’; or TITLEn ‘title text’; FOOTNOTEn ‘footnote text SAS ESSENTIALS -- Elliott & Woodward4 First line of either Title or Footnote Define line 2 to 9 of Titles or Footnotes

TITLE and FOOTNOTES Examples SAS ESSENTIALS -- Elliott & Woodward5 TITLE 'The first line of the title'; TITLE2 'The second line of the title'; TITLES 'Several lines skipped, then this title on the fifth line'; FOOTNOTE 'This is a footnote'; FOOTNOTE3 'This is a footnote, line 3';  Cancel all TITLE and FOOTNOTE lines with the statement TITLE; FOOTNOTE;  Do Hands On Exercise P 114

Customizing Titles and Footnotes SAS ESSENTIALS -- Elliott & Woodward6  There are a number of options that can be used with the TITLE or FOOTNOTE statements to customize the look of your title.  Some of these options include specifying color with a C= or COLOR= option. For example: TITLE C=BLUE H=5 "This is a title";  This title appears in the color (C= or COLOR=) blue with a height (H= or HEIGHT= ) larger than normal.  Do Hands on Example p116.

SAS ESSENTIALS -- Elliott & Woodward7

Including Comments in Your SAS Code  It is a good programming practice to include explanatory comments in your code. There are two options for putting comments in your code  Method 1 - Begin with an asterisk (*), and end with a semi-colon (;). *This is a message It can be several lines long But it always ends with an ; ************************************************************* * Boxed messages stand out more, still end in a semicolon * *************************************************************; DATA MYDATA; * You can put a comment on a line of code; SAS ESSENTIALS -- Elliott & Woodward8

 Comments Method 2 – Begin with /* and end with */ /*This is a SAS comment*/ /* Use this comment technique to comment out lines of code PROC PRINT; PROC MEANS; End of comment – the PROCS were ignored*/ The code from /* to */ Is ignored by SAS SAS ESSENTIALS -- Elliott & Woodward9

Using RUN and QUIT Statements SAS ESSENTIALS -- Elliott & Woodward10  The RUN statement causes previously entered SAS statements to be executed. It is called a boundary statement. For example: PROC PRINT; PROC MEANS; RUN;  Another boundary statement is the QUIT statement. It is sometimes used in conjunction with a RUN statement to cease an active procedure. For example: PROC REG; RUN; QUIT;

5.2 UNDERSTANDING PROC STATEMENT SYNTAX  Although there are scores of SAS PROCs (procedures), the syntax is consistent across all of them. The general syntax of the SAS PROC statement is: PROC name options; Statements/statementoptions;...etc... Statements/statementoptions; RUN ; SAS ESSENTIALS -- Elliott & Woodward11

Four parts of a PROC Statement PROC name options; statements/statementoptions ; The name of the SAS procedure such as MEANS or PRINT. OPTIONS appear BEFORE the semicolon. Typical options are DATA=, NOPRINT, and others – typically deal with the data set or output. STATEMENTS appear as a separate “phrase” (with its on semicolon.) These usually specify options within the procedure. There may be multiple Statements. Statements may have their own options following a slash (/). SAS ESSENTIALS -- Elliott & Woodward12

Example PROC Syntax (Options) SAS ESSENTIALS -- Elliott & Woodward13  The most commonly used option within the PROC statement is the DATA= option. For example: PROC PRINT DATA=MYDATA; RUN;  The DATA= option tells SAS which data set to use in the analysis. Note that options appear in the PROC statement BEFORE the semicolon.

Example PROC Syntax (Statements) SAS ESSENTIALS -- Elliott & Woodward14  Procedure statements are often required to indicate information about how an analysis is to be performed. For example: PROC PRINT DATA=MYDATA; VAR ID GROUP TIMEl TIME2; RUN; STATEMENTS appear AFTER the first PROC semicolon

Example PROC Syntax (Statement Options) SAS ESSENTIALS -- Elliott & Woodward15  Statements can themselves have options. For example: PROC FREQ DATA=MYDATA; TABLES GROUP*SOCIO/CHISQ; RUN; This is a statement option – note that it follows a slach (/) within the Statement

Summary of typical PROC Syntax SAS ESSENTIALS -- Elliott & Woodward16 PROC FREQ DATA=MYDATA; TABLES GROUP*SOCIO/CHISQ; RUN; PROC name PROC option PROC Statement PROC Statement Option

SAS ESSENTIALS -- Elliott & Woodward17

Common PROC options  Some typical options that are COMMON to most PROCS include:  DATA=Specify data set to use in the analysis  NOPRINT Do not display certain output  OUT=Send results to an output data set SAS ESSENTIALS -- Elliott & Woodward18

Common PROC Statements  VAR variable(s);Instructs SAS to use only the variables in the list for the analysis.  BY variable(s); Repeats the procedure for each different value of the named variable(s). (The data set must first be sorted by the variables listed in the BY statement.)  ID variable(s); Instructs SAS to use the specified variable as an observation identifier in a listing of the data.  LABEL var='label'; Assigns a descriptive label to a variable.  WHERE (expression); Instructs SAS to select only those observations for which the expression is true. SAS ESSENTIALS -- Elliott & Woodward19

OPTIONS Specific to a PROC  In PROC MEANS, for example, the MAXDEC option specified how many decimal places to report.  The options specific for PROC will be covered as the PROCS are introduced PROC MEANS DATA=“C:\SASDATA\SOMEDATA” MAXDEC=2; RUN; SAS ESSENTIALS -- Elliott & Woodward20 Notice that BOTH the DATA= and the MAXDEC= options are within the first semicolon.

Using the VAR Statement in a SAS Procedure  The VAR Statement is often used to specify a list of variables to use in an analysis VAR varlist;  An example is as follows: PROC MEANS; VAR HEIGHT WEIGHT AGE; RUN; SAS ESSENTIALS -- Elliott & Woodward21

Listing a range of Variables  List a range of variables with consecutive numeric suffixes such as Q1, Q2, Q3, etc. to Q50 using a single dash between the first and last: Q1-Q50: VAR Q1-Q50;  List a range of variables without consecutive suffixes with two dashes. Example: VAR ID - - TIME4; USE two dashes to indicate all variables between the indicated names SAS ESSENTIALS -- Elliott & Woodward22

Using the BY Statement in a SAS Procedure  The BY statement allows you to quickly analyze subsets of your data. Repeat an analysis for each value in BY (data must be in sorted order by BY variable.) Example: PROC SORT DATA="C:\SASDATA\SOMEDATA" OUT=SORTED; BY GP;RUN; PROC MEANS DATA=SORTED MAXDEC=2; BY GP; RUN; Sort Note OUT= in OPTIONS BY is used first to SORT, then to request analysis by group. SAS ESSENTIALS -- Elliott & Woodward23 BY is used first to SORT, then to request analysis by group.

Do Hands-On Exercise p 121  Sort data sets  Use BY to perform PROC by the indexed value  Multiple results displayed SAS ESSENTIALS -- Elliott & Woodward24 GP is the BY variable… thus multiple analyses BY GP

5.3 USING THE ID STATEMENT IN A SAS PROCEDURE  The ID statement provides you with a way to increase the readability of your output. It instructs SAS to use the specified variable as an observation identifier in a listing of the data (Instead of the OBS column.) * FIRST VERSION; PROC PRINT DATA=MYSASLIB.SOMEDATA;RUN ; * SECOND VERSION; PROC PRINT DATA=MYSASLIB.SOMEDATA; ID SUBJID; RUN; SAS ESSENTIALS -- Elliott & Woodward25 SUBJID is the ID variable

Do Hands On Exercise p 122 SAS ESSENTIALS -- Elliott & Woodward26  Observe Results, first without ID Statement  Second time with ID Statement Notice how the Obs statement was replaced with the RAT_ID column

5.4 USING THE LABEL STATEMENT IN A SAS PROCEDURE  Aversion of the LABEL statement allows you to create labels for variable names within a procedure. LABEL var='label';  Assigns a descriptive label to a variable. Example: PROC PRINT LABEL; ID RAT_ID; LABEL TRT='Treatment'; RUN; NOTE: This assignment of a LABEL only works during this PROC, unlike the LABEL statement in a DATA Step that is saved within the data set. SAS ESSENTIALS -- Elliott & Woodward27

Hands-On Exercise p 124  Example of the LABEL Statement in a PROC  This code: PROC MEANS DATA=WEIGHT; LABEL WT_GRAMS="Treatment" MDATE="MEDOBS Date"; RUN;  Produces this output SAS ESSENTIALS -- Elliott & Woodward28

5.5 USING THE WHERE STATEMENT IN A SAS PROCEDURE  The WHERE statement allows you to specify a conditional criterion for which output will be included in an analysis. Example WHERE TRT="A"; within a PROC statement causes the procedure to only use records in the dataset that match the criteria TRT=“A”. SAS ESSENTIALS -- Elliott & Woodward29

Do Hands On Example p 125  Example of the WHERE statement PROC PRINT LABEL DATA=WEIGHT; ID RAT_ID; LABEL TRT='Treatment ' ; WHERE TRT="A"; RUN; SAS ESSENTIALS -- Elliott & Woodward30 This code produces this output… for only TRT=“A”

5.6 USING PROC PRINT Although several previous examples have used a simple version of the PROC PRINT procedure, a number of options for this procedure have not been discussed. Here are common options: SAS ESSENTIALS -- Elliott & Woodward31

Common Statements for PROC PRINT SAS ESSENTIALS -- Elliott & Woodward32  For example, the SUM statement specifies that a sum of the values for the variables listed is to be reported. SUM COST ;

Do Hands On Example p 127  Using APRINT1.SAS PROC PRINT DATA="C:\SASDATA\SOMEDATA" N = 'Number of Subjects is: ' Obs='Subjects'; SUM TIME1 TIME2 TIME3 TIME4; TITLE 'PROC PRINT Example'; RUN; SAS ESSENTIALS -- Elliott & Woodward33

Output from example showing PROC PRINT options and statement results SAS ESSENTIALS -- Elliott & Woodward34

5.7 GOING DEEPER: SPLITTING COLUMN TITLES IN PROC PRINT SAS ESSENTIALS -- Elliott & Woodward35  Normally, SAS splits titles at blanks when needed to conserve space in a report.  If you want a different look, you can tell SAS where you want the labels to be split using the SPLIT= option. For example: PROC PRINT DATA=SOMEDATASET; SPLIT='*‘ LABEL INC_KEY='Subject*ID*============' AGE='Age in*2014*============' GENDER='Gender* *============‘;  In this code, SAS splits the labels where it sees an asterisk. Do the Hands On Example p 129 (APRINT3.SAS).

Results of using the Split Option SAS ESSENTIALS -- Elliott & Woodward36 Note how the splits for labels occur – according to where the asterisks were in the code.

5.8 GOING DEEPER: COMMON SYSTEM OPTIONS SAS ESSENTIALS -- Elliott & Woodward37  Although not a part of a PROC statement, System Options can be used to customize the way output is displayed or how data in a data set is used.  This section introduces some commonly used options. System Options are specified using the OPTIONS statement. The syntax for the OPTIONS statement is OPTIONS option1 option2... ;  For example OPTIONS ORIENTATION=LANDSCAPE;

Common System Options (See Table 5.14) SAS ESSENTIALS -- Elliott & Woodward38 Common System OptionsMeaning FIRSTOBS=n and OBS=n;Specifies the first observation to be used in a data set (FIRSTOBS=) and the last observation to be used (OBS= ). For example OPTIONS FIRSTOBS=2 OBS=21; causes SAS to use data records 2 through 21 in any subsequent analysis. When this option is set, it is usually a good idea to reset the values to OPTIONS FIRSTOBS=1; OBS=MAX; at the end of the program so subsequent analyses are not limited by the same options. YEAR CUTOFF= yearSpecifies the cutoff year for two digit dates in a 100 year span starting with the specified date. For example if YEARCUTOFF=1920 then the data would be considered 2019 while 01/15/21 would be seen as The default YEARCUTOFF is (For SAS versions 9 through 9.3, the cutoff year was 1920.)

Common System Options (continued) SAS ESSENTIALS -- Elliott & Woodward39 System OptionsMeaning PROBSIG=nSpecifies the number of decimals used when reporting p-values. For example PROBSIG=3 would cause p-values to be reported to three decimal places. LINESIZE= n and PAGESIZE= nControls number of characters in an output line (LINESIZE) or number of lines on a page (PAGESIZE) for RTF and PDF output. NONUMBERSpecifies no page numbers will be included in RTF or PDF output. NODATESpecifies no date will be included in RTF or PDF output. ORIENTATION=optionSpecified paper orientation. Options are PORTRAIT or LANDSCAPE for RTF or PDF output. NOCENTERLeft justifies output (default is centered)

Do Hands On Exercise p 132 SAS ESSENTIALS -- Elliott & Woodward40  (SYSOBS.SAS) OPTIONS FIRSTOBS=11 OBS=20; PROC PRINT LABEL DATA="C:\SASDATA\SOMEDATA"; RUN; OPTIONS FIRSTOBS=1 OBS=MAX ; Sets system option so only records 11 to 20 are used in any future data sets. It is important to reset the options to the defaults to avoid an error in future data sets

5.9 SUMMARY SAS ESSENTIALS -- Elliott & Woodward41  This chapter introduced you to the syntax of SAS procedures in preparation for using specific PROCs discussed in the remainder of the book. It also introduced PROC PRINT and illustrated some of the common options used for this procedure.  Continue to Chapter 6: SAS® ADVANCED PROGRAMMING TOPICS PART 1