1 / 228

Chapter 4

Chapter 4. Producing List Reports. Section 4.1. Getting Started with the PRINT Procedure. Objectives. Generate simple list reports using the PRINT procedure (PROC PRINT). Display selected variables (columns) in a list report. Display selected observations (rows) in a list report.

salena
Download Presentation

Chapter 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 4 Producing List Reports

  2. Section 4.1 Getting Started with the PRINT Procedure

  3. Objectives • Generate simple list reports using the PRINT procedure (PROC PRINT). • Display selected variables (columns) in a list report. • Display selected observations (rows) in a list report. • Display a list report with column totals.

  4. SAS Code/Vocabulary

  5. Overview of PROC PRINT List reports are typically generated with the PRINT procedure. This means that the data set is simply displayed one row after the other. Here is an example of default output from the PRINT procedure. The SAS System Emp Job Obs ID LastName FirstName Code Salary 1 0031 GOLDENBERG DESIREE PILOT 50221.62 2 0040 WILLIAMS ARLENE M. FLTAT 23666.12 3 0071 PERRY ROBERT A. FLTAT 21957.71

  6. Overview of PROC PRINT • You can change the following: • alter titles • revise the column headings • display dollar signs and commas for Salary • remove the OBS column The SAS System Emp Job Obs ID LastName FirstName Code Salary 1 0031 GOLDENBERG DESIREE PILOT 50221.62 2 0040 WILLIAMS ARLENE M. FLTAT 23666.12 3 0071 PERRY ROBERT A. FLTAT 21957.71 4 0082 MCGWIER-WATTS CHRISTINA PILOT 96387.39 5 0091 SCOTT HARVEY F. FLTAT 32278.40 6 0106 THACKER DAVID S. FLTAT 24161.14

  7. Overview of PROC PRINT • You can display • titles and footnotes • descriptive column headings • formatted data values. Salary Report Emp Job Annual Obs ID Last Name First Name Code Salary 1 0031 GOLDENBERG DESIREE PILOT $50,221.62 2 0040 WILLIAMS ARLENE M. FLTAT $23,666.12 3 0071 PERRY ROBERT A. FLTAT $21,957.71 4 0082 MCGWIER-WATTS CHRISTINA PILOT $96,387.39 5 0091 SCOTT HARVEY F. FLTAT $32,278.40 6 0106 THACKER DAVID S. FLTAT $24,161.14 7 0355 BELL THOMAS B. PILOT $59,803.16 8 0366 GLENN MARTHA S. PILOT $120,202.38

  8. Overview of PROC PRINT • You can also display column totals. The SAS System Emp Job Obs ID LastName FirstName Code Salary 1 0031 GOLDENBERG DESIREE PILOT 50221.62 2 0040 WILLIAMS ARLENE M. FLTAT 23666.12 3 0071 PERRY ROBERT A. FLTAT 21957.71 4 0082 MCGWIER-WATTS CHRISTINA PILOT 96387.39 5 0091 SCOTT HARVEY F. FLTAT 32278.40 6 0106 THACKER DAVID S. FLTAT 24161.14 7 0355 BELL THOMAS B. PILOT 59803.16 8 0366 GLENN MARTHA S. PILOT 120202.38 ========= 428677.92

  9. Overview of PROC PRINT You can break your output into groups. The SAS System ------------------------ JobCode=FLTAT ------------------------- Emp Obs ID LastName FirstName Salary 1 0040 WILLIAMS ARLENE M. 23666.12 2 0071 PERRY ROBERT A. 21957.71 3 0091 SCOTT HARVEY F. 32278.40 4 0106 THACKER DAVID S. 24161.14 ------------------------ JobCode=PILOT ------------------------- Emp Obs ID LastName FirstName Salary 5 0031 GOLDENBERG DESIREE 50221.62 6 0082 MCGWIER-WATTS CHRISTINA 96387.39 7 0355 BELL THOMAS B. 59803.16 8 0366 GLENN MARTHA S. 120202.38

  10. Overview of PROC PRINT • You can get subtotals for each group. The SAS System ------------------------ JobCode=FLTAT ------------------------- Emp Obs ID LastName FirstName Salary 1 0040 WILLIAMS ARLENE M. 23666.12 2 0071 PERRY ROBERT A. 21957.71 3 0091 SCOTT HARVEY F. 32278.40 4 0106 THACKER DAVID S. 24161.14 ------- --------- JobCode 102063.37 ------------------------ JobCode=PILOT ------------------------- Emp Obs ID LastName FirstName Salary 5 0031 GOLDENBERG DESIREE 50221.62 6 0082 MCGWIER-WATTS CHRISTINA 96387.39 7 0355 BELL THOMAS B. 59803.16 8 0366 GLENN MARTHA S. 120202.38 ------- --------- JobCode 326614.55 ========= 428677.92

  11. Overview of PROC PRINT You can put the different groups on different pages. The SAS System ------------------------ JobCode=FLTAT ------------------------- Emp Obs ID LastName FirstName Salary 1 0040 WILLIAMS ARLENE M. 23666.12 2 0071 PERRY ROBERT A. 21957.71 3 0091 SCOTT HARVEY F. 32278.40 4 0106 THACKER DAVID S. 24161.14 ------- --------- JobCode 102063.37 The SAS System ------------------------ JobCode=PILOT ------------------------- Emp Obs ID LastName FirstName Salary 5 0031 GOLDENBERG DESIREE 50221.62 6 0082 MCGWIER-WATTS CHRISTINA 96387.39 7 0355 BELL THOMAS B. 59803.16 8 0366 GLENN MARTHA S. 120202.38 ------- --------- JobCode 326614.55 ========= 428677.92

  12. Creating a Default List Report • General form of the PRINT procedure: • Example: PROC PRINT DATA=SAS-data-set;RUN; Remember, you need to submit the LIBNAME statement once in your SAS session. libname ia 'SAS-data-library'; proc print data=ia.empdata; run;

  13. ia.empdata PROC Step Creating a Default List Report libname ia 'SAS-data-library'; proc print data=ia.empdata; run; Print all variables. The SAS System Emp Job Obs ID LastName FirstName Code Salary 1 0031 GOLDENBERG DESIREE PILOT 50221.62 2 0040 WILLIAMS ARLENE M. FLTAT 23666.12 3 0071 PERRY ROBERT A. FLTAT 21957.71

  14. Exercise • This exercise reinforces the concepts discussed previously.

  15. Exercise Use PROC PRINT to create a list report of the ia.newmechs data set.

  16. Exercise proc print data=ia.newmechs; run; Partial Output The SAS System Job Obs LastName FirstName EmpID Code Gender 1 MASSENGILL ANNETTE M. E00007 MECH01 F 2 KEARNEY ANGELA E. E00014 MECH02 F 3 OVERBY JR. WOUTER E00065 MECH02 M 4 WARD ROBERT A. E00074 MECH03 M 5 HICKS CLARENCE C E00095 MECH03 M 6 WANG ROBERT B. E00112 MECH01 M 7 BRUMFIELD JUDITH E00132 MECH02 F 8 BAKER DONALD A. E00151 MECH01 M 9 ROHLOFF PATRICIA J. E00181 MECH02 F 10 OWENS CLAIRE B. E00214 MECH02 F 11 SAWYER STEPHANIE E00216 MECH03 F 12 WALLACE MEI-YIU E00218 F 13 SPENCE MICHAEL E00239 MECH03 M

  17. Creating a Default List Report What is the Obs column? The SAS System Emp Job Obs ID LastName FirstName Code Salary 1 0031 GOLDENBERG DESIREE PILOT 50221.62 2 0040 WILLIAMS ARLENE M. FLTAT 23666.12 3 0071 PERRY ROBERT A. FLTAT 21957.71

  18. Creating a Default List Report • The Obs column helps you identify a row. This is helpful if one row of data cannot fit on one line in your report. SAS breaks the row into "chunks". The Obs column helps you find where the row continues. The SAS System Obs Division HireDate LastName FirstName Country 1 FLIGHT OPERATIONS 11MAR1992 MILLS DOROTHY E USA 2 FINANCE & IT 19DEC1983 BOWER EILEEN A. USA 3 HUMAN RESOURCES 12MAR1985 READING TONY R. USA Job Obs City Phone EmpID Code Salary 1 CARY 2380 E00001 FLTAT3 $25,000 2 CARY 1214 E00002 FINCLK $27,000 3 CARY 1428 E00003 VICEPR $120,000

  19. Suppressing the Obs Column • The NOOBS option suppresses the row numbers on the left side of the report. • General form of the NOOBS option: The Obs column is special to the PRINT procedure. It is not stored with the data. It is for display purposes only. PROC PRINT DATA=SAS-data-set NOOBS;RUN;

  20. PROC Step Suppressing the Obs Column ia.empdata Suppress the Obs column. proc print data=ia.empdata noobs; var JobCode EmpID Salary; run; The SAS System Job Emp Code ID Salary PILOT 0031 50221.62 FLTAT 0040 23666.12 FLTAT 0071 21957.71

  21. Exercise • This exercise reinforces the concepts discussed previously.

  22. Exercise Use PROC PRINT to create a list report of the ia.newmechs data set. Suppress the Obs column.

  23. Exercise proc print data=ia.newmechs noobs; run; Options can be in any order after the procedure name. proc print noobs data=ia.newmechs; run; Partial Output The SAS System Job LastName FirstName EmpID Code Gender MASSENGILL ANNETTE M. E00007 MECH01 F KEARNEY ANGELA E. E00014 MECH02 F OVERBY JR. WOUTER E00065 MECH02 M WARD ROBERT A. E00074 MECH03 M

  24. Printing Selected Variables • What if you do not want all the columns displayed in your output? • What if you want the columns in a different order?

  25. Printing Selected Variables • The VAR statement enables you to • select variables to include in the report • define the order of the variables in the report. • General form of the VAR statement: • Variable names should be separated by a single space. VAR variable(s);

  26. Using Variable Names • SAS variable names are not case sensitive. You can use all lower, upper, or mixed case. • These are considered to be the same. The variable names do not have to match the case that is stored in the descriptor portion. proc print data=ia.empdata; var JobCode EmpID Salary; run; proc print data=ia.empdata; var jobCode empid SALARY; run;

  27. PROC Step Printing Selected Variables ia.empdata Select and order variables to print. proc print data=ia.empdata; var JobCode EmpID Salary; run; The SAS System Job Emp Obs Code ID Salary 1 PILOT 0031 50221.62 2 FLTAT 0040 23666.12 3 FLTAT 0071 21957.71

  28. Printing Selected Variables • Does the VAR statement change what is stored in the data set? • Were the LastName and FirstName variables deleted?

  29. Printing Selected Variables • The PROC PRINT step only displays information based on your syntax. • It does not change what is stored in the underlying data set.

  30. Creating a Default List Report If you submit another PROC PRINT step without a VAR statement, you can see that all the variables are displayed. proc print data=ia.empdata; run; The SAS System Emp Job Obs ID LastName FirstName Code Salary 1 0031 GOLDENBERG DESIREE PILOT 50221.62 2 0040 WILLIAMS ARLENE M. FLTAT 23666.12 3 0071 PERRY ROBERT A. FLTAT 21957.71

  31. Exercise • This exercise reinforces the concepts discussed previously.

  32. Exercise Use the ia.newmechs data set to create a list report with the following variables in the following order: EmpID, FirstName, andLastName

  33. Exercise proc print data=ia.newmechs noobs; var EmpID FirstName LastName; run; Partial Output The SAS System EmpID FirstName LastName E00007 ANNETTE M. MASSENGILL E00014 ANGELA E. KEARNEY E00065 WOUTER OVERBY JR. E00074 ROBERT A. WARD E00095 CLARENCE C HICKS E00112 ROBERT B. WANG E00132 JUDITH BRUMFIELD E00151 DONALD A. BAKER

  34. What if you did not want all of the rows? For example, what if you only want to seethe rows for people who are pilots? What if you want a report of pilotswho make more than $50,000 a year? Subsetting Data: WHERE Statement

  35. Subsetting Data: WHERE Statement • You can use a WHERE statement. • The WHERE statement • enables you to select observations that meet a certain condition or conditions • can be used with most SAS procedures (PROCs).

  36. Subsetting Data: WHERE Statement • General form of the WHERE statement: • where-expression is a sequence of operands and operators. • An operand is the item in the relationship. • The operator describes the relationship. • Example: where LastName = "Jones"; • LastName is an operand and = is the operator. WHEREwhere-expression;

  37. Subsetting Data: WHERE Statement • Operands include the following: • variables (Salary, LastName, JobCode) • constants (the actual values that the WHERE statement compares) ( 5, 'Jones', 50000) • Operators include the following: • comparison operators (=, >=, <, >, <= …) • logical operators (and, or, not) • special operators (between and, contains) • functions (discussed in Chapter 7)

  38. Comparison Operators Mnemonic Symbol Definition You can use the mnemonic or symbol.

  39. Comparison Operators: Examples • The following two examples yield the same result. The first example uses a symbol for greater than (>) and the second example uses the mnemonic (gt). proc print data=ia.empdata2; where Salary >50000; run; proc print data=ia.empdata2; where Salary gt 50000; run;

  40. Comparison Operators - Examples • Output • All the rows in the output represent people who make more than $50,000 a year. Emp Job Obs Id LastName FirstName Code Salary 2 0456 IVEY ANGELA B. FLTAT 62296.30 3 0151 BAKER DONALD A. MECH 63853.70 6 0481 YANG BETTY A. FLTAT 70083.33 7 0342 LEHMAN JUDY L. FLTAT 65411.11 8 0262 WEISS MARY E. PILOT 56066.67 10 0423 DUNHAM DEANNA FLTAT 62296.30 11 0145 KRAMER ALISSA W. PILOT 95001.85 12 0214 OWENS CLAIRE B. MECH 68525.93 13 0316 TAYLOR CHRISTINA PILOT 70083.33

  41. Comparison Operators: Examples Did SAS remove the rows from the data set where the salaries were less than or equal to $50,000?

  42. Remember Comparison Operators: Examples Did SAS remove the rows from the data set where the salaries were less than or equal to $50,000? Answer: No. PROC PRINT does not change data. It simply lists and displays the data in the report.

  43. Remember Comparison Operators - Examples • What does this PROC PRINT code produce? • Character comparisons are case-sensitive. Character strings must be enclosed in matching quotation marks. • PILOT is not the same character string as Pilot. proc print data= ia.empdata2; where JobCode = 'PILOT'; run;

  44. Comparison Operators • Output Emp Job Id LastName FirstName Code Salary 0262 WEISS MARY E. PILOT 56066.67 0402 GOODLING DAVID PILOT 43607.41 0145 KRAMER ALISSA W. PILOT 95001.85 0316 TAYLOR CHRISTINA PILOT 70083.33 0225 VANCE MICHAEL PILOT .

  45. Exercise • This exercise reinforces the concepts discussed previously.

  46. Exercise Use the ia.newmechs data set to createa list report for all the Level 02 mechanics.

  47. Exercise proc print data=ia.newmechs noobs; where jobcode= 'MECH02'; run;

  48. Comparison Operators: Examples • What does this PROC PRINT code produce? • Look at the WHERE statement. Is EmpID a character or numeric variable? Why? proc print data= ia.empdata2 noobs; where EmpID = '0262'; run;

  49. Comparison Operators: Examples • Output • Answer:EmpID is a character string. • It begins with a zero. If it were numeric, SAS would not display the leading zero. • You will not perform calculations on this variable. • It needs quotation marks around the value because it is a character string, but not around the variable name. • How much storage would EmpID take if it were a numeric variable? Emp Job Id LastName FirstName Code Salary 0262 WEISS MARY E. PILOT 56066.67

  50. Remember Comparison Operators: Examples • What does this PROC PRINT produce? • A blankspacemeans a missing value for character values. • A period means a missing value for numeric values. proc print data=ia.empdata2; where Salary =.; run;

More Related