Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1."— Presentation transcript:

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

2 Chapter 18: CREATING CUSTOM REPORTS PART 2 SAS ESSENTIALS -- Elliott & Woodward2

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

4 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.

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

6 SAS ESSENTIALS -- Elliott & Woodward6 Table 19.14 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

7 SAS ESSENTIALS -- Elliott & Woodward7 Table 19.15 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.

8 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.)

9 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.

10 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

11 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';

12 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.

13 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.

14 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.

15 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

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

17 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

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

19 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.

20 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…

21 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

22 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.

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

24 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.

25 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

26 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

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

28 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 ~

29 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

30 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.

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

32 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

33 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

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

35 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

36 Resulting Report for AUTOMATIC SAS ESSENTIALS -- Elliott & Woodward36

37 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

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

39 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

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

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

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

43 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.

44 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.

45 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.

46 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…

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

48 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

49 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”

50 Customizing Lines of Output Using PUT SAS ESSENTIALS -- Elliott & Woodward50 Table 19.24 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 TIME2 TIME3; @n, @var, or @expression Moves the pointer to a specified column location. When using @var or @expression, they must be numeric. For example PUT @5 'Age =' AGE;

51 SAS ESSENTIALS -- Elliott & Woodward51 Table 19.24 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 using @var or @expression, they must be numeric. @Holds 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.

52 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 88.4 91 79 Jones, Steve 99 100 88.4 Zabar,Fred 78.6 87 88.4 ; 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

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

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

55 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; PUT @L TABLEHEAD; PUT @5 60*'='; PUT @5 "NAME" @20 "| TEST 1" @30 "| TEST 2 " @40 "| TEST 3" @50 "| AVERAGE"; PUT @5 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)

56 Grade Report, Part 3 SAS ESSENTIALS -- Elliott & Woodward56 PUT @5 NAME @20 "|" G1 5.1 @30 "|" G2 5.1 @40 "|" G3 5.1 @50 "|" AVE 5.1; IF EOF=1 then do; * PUT FOOTER FOR REPORT; PUT @5 60*'-'; PUT @5 "CLASS AVERAGE " @;*HOLDS LINE FOR NEXT PUT; PUT @50 "| %TRIM(&CLASSMEAN) " ; PUT @5 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 as @20 (column 20) When EOF=1 (after last student grades are put out), put out the footer info. Displays the summary information, CLASSMEAN (macro variable)

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

58 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.

59 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

60 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: 111904216X ISBN-13: 978-1119042167 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 acelliott@smu.edu. Thanks.


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

Similar presentations


Ads by Google