Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to SAS Essentials Mastering SAS for Data Analytics

Similar presentations


Presentation on theme: "Introduction to SAS Essentials Mastering SAS for Data Analytics"— Presentation transcript:

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

2 Chapter 19: CREATING CUSTOM REPORTS PART 2
SAS ESSENTIALS -- Elliott & Woodward

3 19.2 USING PROC REPORT 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 <Opti ons>; COLUMN variables and specifications; DEFINE column / attributes; COMPUTE column; compute statements; ENDCOMP; RUN; SAS ESSENTIALS -- Elliott & Woodward

4 The COLUMN Statement in PROC REPORT
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. SAS ESSENTIALS -- Elliott & Woodward

5 The DEFINE Statement in PROC REPORT
The DEFINE statement is used to specify the appearance of the columns. Its syntax is DEFINE report-item / <Option(s)>; 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 & Woodward

6 Table 19.14 PROC REPORT DEFINE (Report-Items) Name Purpose Display
Display the indicated the variable in the column. This is the default. DEFINE SBP/DISPLAY; Order Sorts data and forms groups Group Group (consolidate) observations using the specified variable. For example DEFINE BRAND/GROUP; Displays records grouped by BRAND. Analysis Defines 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. Across Create groups across page rather than down the page SAS ESSENTIALS -- Elliott & Woodward

7 Table 19.15 PROC REPORT DEFINE Statement Option Attributes Attributes
Example FORMAT = format Example FORMAT=6.1 ‘LABEL’ Example ‘Model Type’ Or ‘Model/Type’ to split title. STATISTICNAME Any 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. SAS ESSENTIALS -- Elliott & Woodward

8 The /DISPLAY Option in the DEFINE Statement
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.) SAS ESSENTIALS -- Elliott & Woodward

9 Resulting Report (Part of Report Shown)
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. SAS ESSENTIALS -- Elliott & Woodward

10 Add DISPLAY options for HWYMPG, and ENGINESIZE
Note 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'; SAS ESSENTIALS -- Elliott & Woodward

11 ORDER Option in the DEFINE Statement
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'; SAS ESSENTIALS -- Elliott & Woodward

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

13 Change Direction 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. SAS ESSENTIALS -- Elliott & Woodward

14 More ORDER options Ordered by Brand, but in by the order
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. SAS ESSENTIALS -- Elliott & Woodward

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

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

17 The GROUP Option in the DEFINE Statement
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 SAS ESSENTIALS -- Elliott & Woodward

18 PROC Report Using GROUP Option Results
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; SAS ESSENTIALS -- Elliott & Woodward

19 Redo the COLUMN statement
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. SAS ESSENTIALS -- Elliott & Woodward

20 Add another DEFINE statement – for HWYMPG
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 & Woodward

21 COLUMN CYLINDERS CITYMPG,MEAN HWYMPG,MEAN;
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 SAS ESSENTIALS -- Elliott & Woodward

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

23 ANALYSIS OPTION in the DEFINE Statement
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; SAS ESSENTIALS -- Elliott & Woodward

24 Initial Report Results
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. SAS ESSENTIALS -- Elliott & Woodward

25 Create a New DEFINE Statement
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 SAS ESSENTIALS -- Elliott & Woodward

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

27 Using the COMPUTE Option
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; SAS ESSENTIALS -- Elliott & Woodward

28 Some New Statements 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. Note the split character ~ This code is used to computer RATIO_MPG. Notice that the variable named _C2_ and _C3_ refer to the 2nd (CITYMPG) and 3rd (HWYMPG) variables in the DEFINE Statement. Thus, the calculation is actually CITYMPG/HWYMPG SAS ESSENTIALS -- Elliott & Woodward

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

30 New CODE required to create the ENG_RATIO column is in RED.
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_; RUN; New CODE required to create the ENG_RATIO column is in RED. SAS ESSENTIALS -- Elliott & Woodward

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

32 The ACROSS Option in the DEFINE Statement
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 SAS ESSENTIALS -- Elliott & Woodward

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

34 Create Another Column (ENGINESIZE)
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 & Woodward

35 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 SAS ESSENTIALS -- Elliott & Woodward

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

37 ADDITIONAL TECHNIQUES for PROC REPORT
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 SAS ESSENTIALS -- Elliott & Woodward

38 Do Hands On Exercise p 453 (AREPORT7.SAS)
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; SAS ESSENTIALS -- Elliott & Woodward

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

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

41 Reporting Totals and Subtotals in PROC REPORT
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 <BEFORE|AFTER> var/SUMMARIZE <SUPPRESS>; For the RBREAK statement, the syntax is RBREAK < BEFORE|AFTER >/SUMMARIZE; SAS ESSENTIALS -- Elliott & Woodward

42 Do Hands On Exercise p 454 (AREPOR7.SAS)
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; SAS ESSENTIALS -- Elliott & Woodward

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

44 Output Without Suppress
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. Notice duplicated names at subtotal … because not suppressed. SAS ESSENTIALS -- Elliott & Woodward

45 WRITING REPORTS IN A DATA STATEMENT
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. SAS ESSENTIALS -- Elliott & Woodward

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

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

48 Change the PUT Statement
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 SAS ESSENTIALS -- Elliott & Woodward

49 Output to a File Destination
DATA _NULL_; SET MYSASLIB.SOMEDATA; FILE "C:\SASDATA\OUTPUT.TXT"; PUT "The Age for Subject " ID " is " AGE; RUN; The contents of the file OUT.TXT 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… 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” SAS ESSENTIALS -- Elliott & Woodward

50 Customizing Lines of Output Using PUT
Table Options for the PUT Statement (PART 1) Option Meaning '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; Moves the pointer to a specified column location. When or @expression, they must be numeric. For example 'Age =' AGE; SAS ESSENTIALS -- Elliott & Woodward

51 Table 19.24 Options for the PUT Statement (PART 2) Option Meaning
+n +var, or +expression Moves the pointer to a relative location n columns to the right from its current location. When 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. SAS ESSENTIALS -- Elliott & Woodward

52 Grade Report Example (Grade Report Part 1)
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; AVE is calculated for the grades (G1 to G3) Average (calculated in PROC MEANS) for each test is stored in the data file GMEAN SAS ESSENTIALS -- Elliott & Woodward

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

54 Do Hands On Example p 458 (APUT_REPORT2.SAS)
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; SAS ESSENTIALS -- Elliott & Woodward

55 Grade Report, Part 2 The report uses information from the GRADES SAS data set. EOF marks the last records in the GRADES data set. 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; 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) SAS ESSENTIALS -- Elliott & Woodward

56 Displays the summary information, CLASSMEAN (macro variable)
Grade Report, Part 3 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) "|" 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; When EOF=1 (after last student grades are put out), put out the footer info. Displays the summary information, CLASSMEAN (macro variable) SAS ESSENTIALS -- Elliott & Woodward

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

58 Continue the Exercise…
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. SAS ESSENTIALS -- Elliott & Woodward

59 SUMMARY 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 & Woodward

60 These slides are based on the book:
Introduction to SAS Essentials Mastering SAS for Data Analytics, 2nd 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. SAS ESSENTIALS -- Elliott & Woodward


Download ppt "Introduction to SAS Essentials Mastering SAS for Data Analytics"

Similar presentations


Ads by Google