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

Slides:



Advertisements
Similar presentations
Benchmark Series Microsoft Excel 2013 Level 2
Advertisements

Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
System Design System Design - Mr. Ahmad Al-Ghoul System Analysis and Design.
Copyright 2003 Peter McDevitt 1 Microsoft Excel 2002 Lecture 3 – A Professional Looking Worksheet.
® Microsoft Office 2010 Word Tutorial 3 Creating a Multiple-Page Report.
COMPREHENSIVE ICT Document Preparation System Mr.S.Sajiharan Computer Unit Faculty of Arts and Culture South Eastern University of Srilanka.
Developing Effective Reports
Introduction to SQL Session 1 Retrieving Data From a Single Table.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Word Tutorial 3 Creating a Multiple-Page Report
Advanced Tables Lesson 9. Objectives Creating a Custom Table When a table template doesn’t suit your needs, you can create a custom table in Design view.
XP 1 Microsoft Office Excel 2003 Tutorial 3 – Working With Excel Lists.
Developing Effective Reports
Introduction to SAS Essentials Mastering SAS for Data Analytics
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.
PROC REPORT organizes the output in many ways, from the simple to highly complex… PROC REPORT NOWINDOWS HEADLINE HEADSKIP; COLUMN variable-list; DEFINE.
October 2003Bent Thomsen - FIT 3-21 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Introduction to SAS Essentials Mastering SAS for Data Analytics
1 Data List Spreadsheets or simple databases - a different use of Spreadsheets Bent Thomsen.
XP Agenda Video Last Class Excel Tutorial 5: Working with Excel Lists Agenda for Next Class 1 New Perspectives on Microsoft Office Excel 2003 Tutorial.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
XP New Perspectives on Microsoft Word 2002 Tutorial 31 Microsoft Word 2002 Tutorial 3 – Creating a Multiple-Page Report.
Introduction to SAS Essentials Mastering SAS for Data Analytics
WINKS 7 Tutorial 7 – Advanced Topic: Labels and Formats Permission granted for use for instruction and for personal use. © Alan C. Elliott,
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
FIRST COURSE Word Tutorial 3 Creating a Multiple-Page Report.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Database Applications – Microsoft Access Lesson 7 Designing Custom Reports Updated 11/13 27 Slides in Presentation.
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.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 8 – Adding and.
Microsoft® Excel Key and format dates and times. 1 Use Date & Time functions. 2 Use date and time arithmetic. 3 Use the IF function. 4 Create.
Chapter 5 Working with Multiple Worksheets and Workbooks
1 Lesson 13 Organizing and Enhancing Worksheets Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Working with Data Lists.
Chapter 14 Formatting Readable Output. Chapter Objectives  Add a column heading with a line break to a report  Format the appearance of numeric data.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Microsoft Word 2010 Chapter 2 Creating a Research Paper with Citations and References.
Microsoft® Excel Create an Excel table. 1 Work with the Table Tools Design tab. 2 Sort and filter records in a table. 3 Identify structured references.
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.
Customizing Reports Adding a Date to a Report Reference Window Adding a Date to a Report Display the report in the design view Click the Text Box Tool.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
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.
Extracting Information from an Excel List The purpose of creating a database, or list in Excel, is to be able to manipulate the data elements in ways that.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
A Guide to SQL, Sixth Edition 1 Chapter 7 Reports.
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.
Session 1 Retrieving Data From a Single Table
Applied Business Forecasting and Regression Analysis
Tutorial 3 – Creating a Multiple-Page Report
Structured COBOL Programming
CHAPTER 17 The Report Writer Module
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Bent Thomsen Institut for Datalogi Aalborg Universitet
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Lesson 13 Working with Tables
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 18: CREATING CUSTOM REPORTS PART 2 SAS ESSENTIALS -- Elliott & Woodward2

19.2 USING PROC REPORT SAS ESSENTIALS -- Elliott & Woodward3  PROC REPORT is a procedure in SAS that allows you to create professional data reports and summaries.  The syntax for PROC REPORT is a little different from most statistical procedures because it has a particular emphasis on defining the columns of the report: PROC REPORT DATA: sasdataset ; COLUMN variables and specifications; DEFINE column / attributes; COMPUTE column; compute statements; ENDCOMP; RUN;

The COLUMN Statement in PROC REPORT SAS ESSENTIALS -- Elliott & Woodward4  The COLUMN statement is used to identify variables of interest to be reported in columns and to specify headers and groups. Every column you want to display in the table must be indicated in the COLUMN statement. A simple report would be PROC REPORT DATA:MYSASLIB.CARS NOFS; COLUMN BRAND CITYMPG HWYMPG; RUN;  which is about the same as a PROC PRINT. To enhance the report requires a DEFINE statement.

The DEFINE Statement in PROC REPORT SAS ESSENTIALS -- Elliott & Woodward5  The DEFINE statement is used to specify the appearance of the columns. Its syntax is DEFINE report-item / ;  DEFINE specifies variable attributes that determine how it is displayed. Options follow a slash(/).  Options can be of several types: options that describe how to use a variable; options that control column headings; options that customize a report item; other options for a report item.  For example: DEFINE AGE/DISPLAY 'A Label' FORMAT=6.1;

SAS ESSENTIALS -- Elliott & Woodward6 Table PROC REPORT DEFINE (Report-Items) NamePurpose DISPLAYDisplay the indicated the variable in the column. This is the default. DEFINE SBP/DISPLAY; ORDERSorts data and forms groups GROUPGroup (consolidate) observations using the specified variable. For example DEFINE BRAND/GROUP; Displays records grouped by BRAND. ANALYSISDefines a variable used to calculate a statistic within the cell of a report. COMPUTE and ENDCOMP Begins and ends a code segments that calculates a data value. ACROSSCreate groups across page rather than down the page

SAS ESSENTIALS -- Elliott & Woodward7 Table PROC REPORT DEFINE Statement Option Attributes AttributesExample FORMAT = formatExample FORMAT=6.1 ‘LABEL’Example ‘Model Type’ Or ‘Model/Type’ to split title. STATISTICNAMEAny statistic that is available in PROC MEANS. For example N, MEAN, SUM, or STD. ORDER=ordertype(DATA, FORMATTED, FREQ or INTERNAL) same as in PROC FREQ. Use DESCENDING option to reverse normal ascending order.

The /DISPLAY Option in the DEFINE Statement SAS ESSENTIALS -- Elliott & Woodward8  The DEFINE var/DISPLAY option in the DEFINE statement allows you to specify attributes for that variable including format and labels. This is illustrated in the following example.  Do Hands On Example p 445 (AREPORT1.SAS) PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND MODEL CITYMPG HWYMPG; DEFINE CITYMPG/DISPLAY FORMAT=6.1'CITY/MPG'; RUN;  Note: The NOFS option turns off an older option that is rarely used nowadays. We do not discuss it here.)

Resulting Report (Part of Report Shown) SAS ESSENTIALS -- Elliott & Woodward9 Note the columns shown are because of COLUMN BRAND MODEL CITYMPG HWYMPG; The DISPLAY option CITYMPG/DISPLAY FORMAT=6.1'CITY/MPG formatted this column.

Add DISPLAY options for HWYMPG, and ENGINESIZE SAS ESSENTIALS -- Elliott & Woodward10 COLUMN BRAND MODEL CITYMPG HWYMPG ENGINESIZE; DEFINE CITYMPG/DISPLAY FORMAT=6.1 'CITY/MPG'; DEFINE HWYMPG/DISPLAY FORMAT=6.1 'HWY/MPG'; DEFINE ENGINESIZE/DISPLAY FORMAT=6.1 'ENGINE/SIZE'; Note

ORDER Option in the DEFINE Statement SAS ESSENTIALS -- Elliott & Woodward11  The DEFINE var I ORDER option defines a column variable used to sort the data. Use the DESCENDING opttion to reverse the order.  Do Hands On Exercise p 446 (AREPORT2.SAS) PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND CITYMPG HWYMPG; DEFINE BRAND/ORDER 'Brand'; DEFINE CITYMPG/DISPLAY FORMAT=6.1 'City MPG'; DEFINE HWYMPG/DISPLAY FORMAT=6.1 'Highway MPG';

Result of Order SAS ESSENTIALS -- Elliott & Woodward12  Note that the DEFINE BRAND/ORDER  statement caused the report to be ordered by BRAND, with ACURA as the first brand listed.

Change Direction SAS ESSENTIALS -- Elliott & Woodward13  Change the order direction by putting DESCENDING after BRAND/ORDER. BRAND/ORDER DESCENDING  Rerun and verify that now VOLVO appears as the first brand in the report.

More ORDER options SAS ESSENTIALS -- Elliott & Woodward14  Replace the DESCENDING with ORDER=DATA so that it reads DEFINE BRAND/ORDER ORDER=DATA 'Brand‘  Ordered by Brand, but in by the order in which each brand was originally in the data set. Toyota was the first in the data set.

Use Two ORDER Options… SAS ESSENTIALS -- Elliott & Woodward15 COLUMN BRAND CITYMPG HWYMPG CYLINDERS; DEFINE BRAND/ORDER ODER=DATA 'Brand'; DEFINE CYLINDERS /ORDER 'Cylinders'; Ordered by CYLINDERS within BRAND

Remove the ORDER=DATA, Rerun SAS ESSENTIALS -- Elliott & Woodward16  Now back to Alphabetic Order of BRAND

The GROUP Option in the DEFINE Statement SAS ESSENTIALS -- Elliott & Woodward17  The DEFINE var/GROUP option causes the table to be grouped by the specified variable.  Do Hands On Example p 448 (AREPORT3.SAS) PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND (CITYMPG HWYMPG), MEAN; DEFINE BRAND/GROUP; DEFINE CITYMPG/DISPLAY FORMAT=6.1 'CITY MPG'; RUN; Requests MEAN for both CITYMPG and HWYMPG Assigns a format to CITYMPG

PROC Report Using GROUP Option Results SAS ESSENTIALS -- Elliott & Woodward18 Report is grouped by Brand because of the statement DEFINE BRAND/GROUP; Notice that the format defined for MEAN for CityMPG is also used for HwyMPG because of the statement COLUMN BRAND (CITYMPG HWYMPG), MEAN;

Redo the COLUMN statement SAS ESSENTIALS -- Elliott & Woodward19 COLUMN BRAND CITYMPG,MEAN HWYMPG,MEAN; Because the COLUMN statement now has CITYMPG and HWYMPG separate for MEAN, the Format assigned for CITYMPG only applies to CITYMPG.

Add another DEFINE statement – for HWYMPG SAS ESSENTIALS -- Elliott & Woodward20  DEFINE HWYMPG/DISPLAY FORMAT=6.1 'Highway MPG'; Now, Because there are two DEFINE statements, one for CITYMPG and one for HWYMPG, both means are formatted as desired…

SAS ESSENTIALS -- Elliott & Woodward21  Change BRAND to CYLINDERS in both the COLUMN and DEFINE statements. Rerun and verify that the report is now grouped by number of CYLINDERS COLUMN CYLINDERS CITYMPG,MEAN HWYMPG,MEAN; DEFINE CYLINDERS/GROUP; A Cylinder= - 1 means a rotary engine. Report now grouped by number of Cylinders

Add N Option and ORDER=FREQ SAS ESSENTIALS -- Elliott & Woodward22 COLUMN CYLINDERS N CITYMPG,MEAN HWYMPG,MEAN; DEFINE CYLINDERS/GROUP ORDER=FREQ; Now ordered by frequency, and with an N (count) column.

ANALYSIS OPTION in the DEFINE Statement SAS ESSENTIALS -- Elliott & Woodward23  The DEFINE var/ ANALYSIS option allows you to display a statistic for a specified column.  Do Hands On Example p 449 (AREPORT4.SAS) PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND CITYMPG HWYMPG; DEFINE BRAND/GROUP; DEFINE CITYMPG/ANALYSIS MEAN FORMAT=6.1 'CITY/MPG'; RUN;

Initial Report Results SAS ESSENTIALS -- Elliott & Woodward24 Because of the code DEFINE CITYMPG/ ANALYSIS MEAN FORMAT=6.1 'CITY/MPG'; The CITYMPG MEAN is formatted with 6.1, but HWYMPG is not changed, and the SUM is reported.

Create a New DEFINE Statement SAS ESSENTIALS -- Elliott & Woodward25  Create a DEFINE statement (with ANALYSIS) that causes the mean HWYMPG to be displayed with a 6.1 format and with an appropriate label. DEFINE HWYMPG/ANALYSIS MEAN FORMAT=6.1 'HWY/MPG'; With HWYMPG also in a DEFINE /ANALYSIS statement, it’s mean is also now displayed in 6.1 format

Include ENGINESIZE (Mean) in the REPORT SAS ESSENTIALS -- Elliott & Woodward26 COLUMN BRAND CITYMPG HWYMPG ENGINESIZE; DEFINE ENGINESIZE/ANALYSIS MEAN FORMAT=6.1 'Engine Size'; ENGINESIZE (mean) now also a column

Using the COMPUTE Option SAS ESSENTIALS -- Elliott & Woodward27  COMPUTE and ENDCOMP begin and end a segment of SAS code that allows you to calculate values of new variables.  Do Hands On Example p 450. (AREPORT5.SAS) PROC REPORT DATA=MYSASLIB.CARS NOFS SPLIT="~"; COLUMN BRAND CITYMPG,MEAN HWYMPG, MEAN RATIO_MPG; DEFINE BRAND/ORDER; DEFINE BRAND/GROUP; DEFINE CITYMPG/DISPLAY FORMAT=6.1 'City MPG'; DEFINE HWYMPG/DISPLAY FORMAT=6.1 'Highway MPG'; DEFINE RATIO_MPG/COMPUTED FORMAT=6.2 'Ratio~CITY/HWY'; COMPUTE RATIO_MPG; RATIO_MPG=_C2_/_C3_; ENDCOMP; RUN;

Some New Statements SAS ESSENTIALS -- Elliott & Woodward28 PROC REPORT DATA=MYSASLIB.CARS NOFS SPLIT="~"; DEFINE RATIO_MPG/ COMPUTED FORMAT=6.2 'Ratio~CITY/HWY'; COMPUTE RATIO_MPG; RATIO_MPG=_C2_/_C3_; ENDCOMP; A SPLIT character is defined in the PROC REPORT statement (SPLIT= ”~ ”), COMPUTED indicates that the variable RATIO_MPG is NOT in the data set, but is computed. This code is used to computer RATIO_MPG. Notice that the variable named _C2_ and _C3_ refer to the 2 nd (CITYMPG) and 3 rd (HWYMPG) variables in the DEFINE Statement. Thus, the calculation is actually CITYMPG/HWYMPG Note the split character ~

Results from CALCULATED Example SAS ESSENTIALS -- Elliott & Woodward29 Note the results of the calculated value The split character ~ in the label Ratio~CITY/HWY caused the split to occur after the word Ratio

SAS ESSENTIALS -- Elliott & Woodward30  Create a new column named Engine Ratio based on the calculation CITYMPG/ENGINESIZE. PROC REPORT DATA=MYSASLIB.CARS NOFS SPLIT="~"; COLUMN BRAND CITYMPG,MEAN HWYMPG, MEAN ENGINESIZE, MEAN RATIO_MPG ENG_RATIO; DEFINE BRAND/ORDER; DEFINE BRAND/GROUP; DEFINE CITYMPG/DISPLAY FORMAT=6.1 'City MPG'; DEFINE HWYMPG/DISPLAY FORMAT=6.1 'Highway MPG'; DEFINE RATIO_MPG/COMPUTED FORMAT=6.2 'Ratio~CITY/HWY'; DEFINE ENG_RATIO/COMPUTED FORMAT=6.2 'Engine~Ratio'; COMPUTE RATIO_MPG; RATIO_MPG=_C2_/_C3_; ENDCOMP; COMPUTE ENG_RATIO; ENG_RATIO=_C2_/_C4_; ENDCOMP; RUN; New CODE required to create the ENG_RATIO column is in RED.

Results of Adding ENG_RATIO column SAS ESSENTIALS -- Elliott & Woodward31 Note new ENG_RATIO column

The ACROSS Option in the DEFINE Statement SAS ESSENTIALS -- Elliott & Woodward32  DEFINE var/ ACROSS allows you to create a column for each unique item for a categorical variable.  Do the Hands On Example p 451 (AREPORT6.SAS) PROC FORMAT; VALUE FMTSUV 0="NOT SUV" 1="SUV"; PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND CITYMPG,SUV HWYMPG,SUV; DEFINE BRAND/ORDER; DEFINE BRAND/GROUP; DEFINE CITYMPG/ANALYSIS MEAN FORMAT=6.1; DEFINE HWYMPG/ANALYSIS MEAN FORMAT=6.1; DEFINE SUV/ ACROSS 'BY SUV'; FORMAT SUV FMTSUV.; RUN; Indicates breakdown of variable by categories of SUV

Results of ACROSS Option SAS ESSENTIALS -- Elliott & Woodward33 Notice how CITYMPG and HWYMPG are reported in categories NOTSUV and SUV across each main variable.. (i.e., the column is split into categories) DEFINE SUV/ ACROSS 'BY SUV'; FORMAT SUV FMTSUV.; Where the FORMAT for SUV was defined in a PROC FORMAT statement

Create Another Column (ENGINESIZE) SAS ESSENTIALS -- Elliott & Woodward34  Create another column for ENGINESIZE were the sizes are listed across the table by SUV. New code needed: COLUMN BRAND CITYMPG,SUV HWYMPG,SUV ENGINESIZE,SUV; DEFINE ENGINESIZE/ ANALYSIS MEAN FORMAT=6.1 Note new ENGINESIZE column broken down by SUV (across)

SAS ESSENTIALS -- Elliott & Woodward35  Change all of the SUV references to AUTOMATIC to compare MPG and ENGINESIZE for cars with and without automatic transmissions. PROC FORMAT; VALUE FMTSUV 0="NOT SUV" 1="SUV"; VALUE FMTAUTO 0="Manual" 1="Automatic"; PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND CITYMPG, AUTOMATIC HWYMPG,AUTOMATIC ENGINESIZE,AUTOMATIC; DEFINE BRAND/ORDER; DEFINE BRAND/GROUP; DEFINE CITYMPG/ANALYSIS MEAN FORMAT=6.1; DEFINE HWYMPG/ANALYSIS MEAN FORMAT=6.1; DEFINE ENGINESIZE/ANALYSIS MEAN FORMAT=6.1; DEFINE AUTOMATIC/ ACROSS 'BY SUV'; FORMAT AUTOMATIC FMTAUTO.; RUN; Changes in RED

Resulting Report for AUTOMATIC SAS ESSENTIALS -- Elliott & Woodward36

ADDITIONAL TECHNIQUES for PROC REPORT SAS ESSENTIALS -- Elliott & Woodward37  There are several other ways you can enhancethe output of your report.  Reporting Multiple Statistics: In the COLUMN statement, you can request multiple statistics for a variable by placing a request in parenthesis. For example COLUMN BRAND CITYMPG, (N MEAN STD) ; Requests multiple statistics

Do Hands On Exercise p 453 (AREPORT7.SAS) SAS ESSENTIALS -- Elliott & Woodward38 TITLE "PROC REPORT Multiple Statistics"; PROC RBPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND CITYMPG, (N MEAN STD) HWYMPG ENGINESIZE DEFINE BRAND/GROUP; DEFINE CITYMPG/ FORMAT=6. 1 'City MPG'; DEFINE N/ 'N' format=4.; DEFINE HWYMPG/ ANALYSIS MEAN FORMAT=6.1; DEFINE ENGINESIZE/ ANALYSIS MEAN FORMAT=6. 1 ; RUN;

Initial Output from PROC REPORT SAS ESSENTIALS -- Elliott & Woodward39 Note multiple statistics in the City MPG column because of the entry CITYMPG,(N MEAN STD) In the COLUMN statement

Create similar columns for HWYMPG and ENGINESIZE SAS ESSENTIALS -- Elliott & Woodward40  Change the COLUMN statement to COLUMN BRAND CITYMPG,(N MEAN STD) HWYMPG,(N MEAN STD) ENGINESIZE,(N MEAN STD);

Reporting Totals and Subtotals in PROC REPORT SAS ESSENTIALS -- Elliott & Woodward41  To display totals at the bottom of a column of numbers, use the BREAK and RBREAK statements.  BREAK produces a summary at a specified break  RBREAK specifies a summary at the beginning or end of a report.  A simplified BREAK statement syntax is: BREAK var/SUMMARIZE ;  For the RBREAK statement, the syntax is RBREAK /SUMMARIZE;

Do Hands On Exercise p 454 (AREPOR7.SAS) SAS ESSENTIALS -- Elliott & Woodward42 PROC REPORT DATA=MYSASLIB.CARS NOFS; COLUMN BRAND CYLINDERS AUTOMATIC SUV; DEFINE BRAND/GROUP; DEFINE CYLINDERS/GROUP; BREAK AFTER BRAND/SUMMARIZE SUPPRESS; RBREAK AFTER/ SUMMARIZE ; WHERE CYLINDERS NE -1 ; RUN ;

BREAK and RBREAK Output SAS ESSENTIALS -- Elliott & Woodward43  BREAK is used to count the number of cars that are automatic or are SUV’s  RBREAK creates a grand total.

Output Without Suppress SAS ESSENTIALS -- Elliott & Woodward44  To see what the SUPPRESS option does in the BREAK statement, delete SUPRESS and rerun the code Notice duplicated names at subtotal … because not suppressed.

WRITING REPORTS IN A DATA STATEMENT SAS ESSENTIALS -- Elliott & Woodward45  Another way to create reports in a SAS data set is using the PUT statement: 1. Specify the name _NULL_ as the data set name in a DATA step to use the features of the DATA step without creating a SAS data set as output. 2. Define a destination (output file) for the report using a FILE statement. The statement FILE PRINT sends the report output to the SAS Results Viewer. When you use FILE "file-specification," the report output is sent to the specified text file location. 3. Use PUT statements within the DATA step to create lines of output for the report.

Do Hands On Exercise p 455 (APUT_REPORT1.SAS) SAS ESSENTIALS -- Elliott & Woodward46 DATA _NULL_; SET MYSASLIB.SOMEDATA; PUT AGE; RUN; Very simple PUT statement report. Output is sent to the LOG since no other destination is defined. Results reported in the LOG … a list of ages…

Specify an Output Destination – Results Viewer SAS ESSENTIALS -- Elliott & Woodward47 DATA _NULL_; SET MYSASLIB.SOMEDATA; FILE PRINT; PUT AGE; RUN; … and so on… Specified output destination – the Results Viewer Now the listing of AGEs appears in the Results Viewer…

Change the PUT Statement SAS ESSENTIALS -- Elliott & Woodward48 DATA _NULL_; SET MYSASLIB.SOMEDATA; FILE PRINT; PUT "The Age for Subject " ID " is " AGE; RUN; The Age for Subject 101 is 12 The Age for Subject 102 is 11 The Age for Subject 110 is 12 The Age for Subject 187 is 11 The Age for Subject 312 is 4 The Age for Subject 390 is 6 The Age for Subject 445 is 12 …and so on… Notice how ID and AGE are NOT in quotes – which makes their values reported for each record. This is how the report now appears in the Results Viewer

Output to a File Destination SAS ESSENTIALS -- Elliott & Woodward49 DATA _NULL_; SET MYSASLIB.SOMEDATA; FILE "C:\SASDATA\OUTPUT.TXT"; PUT "The Age for Subject " ID " is " AGE; RUN; The Age for Subject 101 is 12 The Age for Subject 102 is 11 The Age for Subject 110 is 12 The Age for Subject 187 is 11 The Age for Subject 312 is 4 The Age for Subject 390 is 6 …and so on… The contents of the file OUT.TXT Aside – if your file location path is different, use that in the FILE statement. For example in a CITRIX implementation of SAS you might use FILE “\\CLIENT\C$\OUT.SAS”

Customizing Lines of Output Using PUT SAS ESSENTIALS -- Elliott & Woodward50 Table Options for the PUT Statement (PART 1) OptionMeaning 'text' Information in quotes is output verbatim (unless macro variables are within the quotes.) For example PUT 'Some Text'; Variablename(s) The value of a variable for each record in the data set is output where a variable name is included, not in quotes. For example PUT TIME1 Moves the pointer to a specified column location. When they must be numeric. For example 'Age =' AGE;

SAS ESSENTIALS -- Elliott & Woodward51 Table Options for the PUT Statement (PART 2) OptionMeaning +n +var, or +expressionMoves the pointer to a relative location n columns to the right from its current location. When they must be the output on the current output line. The default is to move to the next line of output. var format.A format specification following a variable causes the variable to be displayed with the specified format. For example PUT AGE 5.1; displays the value of AGE using a 5.1 format. n*'char'; Repeats a character n times. For example, PUT 50*'-'; creates a dashed line 50 characters wide.

Grade Report Example (Grade Report Part 1) SAS ESSENTIALS -- Elliott & Woodward52  Using a data set of grades, create a report that includes each student’s grade average, and a class average. AVE is calculated for each student: DATA GRADES; INPUT NAME $15. G1 G2 G3; AVE=MEAN(of G1-G3); DATALINES; Alice, Adams Jones, Steve Zabar,Fred ; RUN; PROC MEANS DATA=GRADES NOPRINT; OUTPUT OUT=GMEAN; RUN; AVE is calculated for the grades (G1 to G3) Average (calculated in PROC MEANS) for each test is stored in the data file GMEAN

Results (so far) SAS ESSENTIALS -- Elliott & Woodward53  Numbers needed for an upcoming Grade Report… Average of all grades Average of each test (G1, G2 and G3)

Do Hands On Example p 458 (APUT_REPORT2.SAS) SAS ESSENTIALS -- Elliott & Woodward54  Using the data set GMEAN (previously created), use this code to create a macro variable named CLASSMEAN that contains the MEAN value from the GMEAN data set, rounded to 1 decimal point. DATA _NULL_;SET GMEAN; IF _STAT_="MEAN" THEN CALL SYMPUT('CLASSMEAN',ROUND(AVE,.01)); RUN;

Grade Report, Part 2 SAS ESSENTIALS -- Elliott & Woodward55 DATA _NULL;SET GRADES END=EOF; TABLEHEAD="SUMMARY OF GRADES"; FILE PRINT; IF _N_= 1 then DO; L=5+(60-LENGTH(TABLEHEAD))/2; * CENTER HEADER; TABLEHEAD; 60*'='; "| TEST "| TEST 2 "| TEST "| AVERAGE"; 60*'-'; END; The report uses information from the GRADES SAS data set. EOF marks the last records in the GRADES data set. If first record (_N_=1) in GRADES, put out header lines for the report. The variable L is the number of spaces to move over so the title is centered Each PUT in this section puts out a line of information for the header. It is only done once at the first records in GRADES (_N_=1)

Grade Report, Part 3 SAS ESSENTIALS -- Elliott & Woodward56 "|" G1 "|" G2 "|" G3 "|" AVE 5.1; IF EOF=1 then do; * PUT FOOTER FOR REPORT; 60*'-'; "CLASS AVERAGE LINE FOR NEXT PUT; "| %TRIM(&CLASSMEAN) " ; 60*'='; END; RUN; This code puts out the body of the report… one line for each student. Note each grade is put out in a certain column according to a pointer such (column 20) When EOF=1 (after last student grades are put out), put out the footer info. Displays the summary information, CLASSMEAN (macro variable)

Resulting Grade Report SAS ESSENTIALS -- Elliott & Woodward57 Look back at the code to see where these student averages and overall Class Average came from…

Continue the Exercise… SAS ESSENTIALS -- Elliott & Woodward58 2. Add a new student to the data, and rerun to see how the table adapts to new information. Rerun the code to verify that your change works correctly. Are the new averages calculated correctly? 3. Change the format for the student averages to 6.2. Rerun the code to verify that your change works correctly.

SUMMARY SAS ESSENTIALS -- Elliott & Woodward59  This concludes the main chapters in the text. Refer to the Appendices for additional information:  Appendix A - Options Reference (Colors, lines, patterns, etc)  Appendix B - SAS Function Reference  Appendix C - Choosing a SAS Procedure (What SAS PROC should I use?)  Appendix D - Quick Reference (Snippets of SAS code)  Appendix E - Using SAS University Edition with SAS® Essentials

SAS ESSENTIALS -- Elliott & Woodward60 These slides are based on the book: Introduction to SAS Essentials Mastering SAS for Data Analytics, 2 nd Edition By Alan C, Elliott and Wayne A. Woodward Paperback: 512 pages Publisher: Wiley; 2 edition (August 3, 2015) Language: English ISBN-10: X ISBN-13: These slides are provided for you to use to teach SAS using this book. Feel free to modify them for your own needs. Please send comments about errors in the slides (or suggestions for improvements) to Thanks.