Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

A Step-By-Step Introduction to SAS Report Procedure

2.538 visualizaciones

Publicado el

The presentation of data is an essential part of every analytics project and there are number of tools within SAS that allows to create a large variety of charts, reports, and data summaries.
PROC REPORT is a particularly powerful and valuable procedure that can be used in this process. It can be used to both summarize and display data, and is highly customizable and highly flexible. It combines features of the PRINT, MEANS, and TABULATE procedures with features of the DATA step.
Here is a step by step introduction to Report Procedure which walks through the PROC REPORT statement and a few of its key options.

Publicado en: Datos y análisis
  • Inicia sesión para ver los comentarios

A Step-By-Step Introduction to SAS Report Procedure

  1. 1. The REPORT Procedure Seema Shelke
  2. 2. Learning Objectives • Create a listing report • Select columns for your report • Define the usage for columns • Specify attributes, options, and justification for columns • Specify features of column headings, including split characters, underlining, and blank lines.
  3. 3. Features  PROC REPORT enables you to • create listing reports • create summary reports • enhance reports • request separate subtotals and grand totals • calculate columns • generate reports in an interactive point-and-click or programming environments.
  4. 4. Creating a Default List Report General form of a simple PROC REPORT step: PROC REPORT <DATA=SAS-data-set> <options>; RUN; Options includes: WINDOWS | WD invokes the procedure in an interactive REPORT window (default). NOWINDOWS | NOWD displays the report in the OUTPUT window.
  5. 5. Sample Data used for reporting • The mylib.fitness dataset contains the medical records for a sample of patients. • This dataset contains variables such as PatID, First_Name, Last_Name,Gender, Age, Height, Weight,Smoking,and Race.
  6. 6. Creating a Default List Report proc report data=mylib.fitness ; run; proc report data=mylib.fitness nowd; run; SAS Listing Output
  7. 7. Creating a Default List Report SAS HTML Output:
  8. 8. The REPORT Procedure  The PROC Report displays • each data value the way it is stored in the data set, or formatted value if a format is stored with the data • variable names or labels as report column headings • a default width for the report columns • character values left-justified • numeric values right-justified • observations in the order in which they are stored in the data set.
  9. 9. Selecting Variables Use a COLUMN statement to select and order the variables that appear in the report. General form of the COLUMN statement: COLUMN variable(s); where variable(s) is one or more variable names, separated by blanks.
  10. 10. Selecting Variables proc report data=mylib.fitness nowd ; column patid gender age height_cm weight_kg; run; SAS Output
  11. 11. Selecting Observations  Use WHERE statement to select the observations for your report. proc report data=mylib.fitness nowd; column patid gender race age height_cm weight_kg; where race in ('Black' ,'Asian'); run; SAS Output Displays only the records where race is Black or Asian
  12. 12. The DEFINE Statement  You can enhance the report by using DEFINE statements to • define how each variable is used in the report • assign formats to variables • specify column headings and column widths • justify the variable values and column headings within the report columns • change the order of the rows in the report.
  13. 13. The DEFINE Statement General form of the DEFINE statement: DEFINE variable / <usage> <attribute(s)> <option(s)> <justification> <'column-heading'> ; Where, • variable is the name of the variable to define. • usage specifies how to use the variable. Valid options are ACROSS, ANALYSIS, COMPUTED, DISPLAY, GROUP, and ORDER. • attribute(s) specifies attributes for the variable, including FORMAT=, WIDTH=, and SPACING=. • option(s) specifies formatting options, including DESCENDING, NOPRINT, NOZERO, and PAGE. • <justification> specifies column justification (CENTER, LEFT, or RIGHT). • 'column-heading' specifies a label for the column heading.
  14. 14. Defining Column Attributes If there is a format stored in the descriptor portion of the data set, it is the default format. The default column width is, • the variable’s length for character variables • 9 for numeric variables • the format width if there is a format stored in the descriptor portion of the data set. WIDTH= column-width : specifies the width of a column. FORMAT= format : assigns a format to a variable.
  15. 15. Defining Column Attributes If there is a label stored in the descriptor portion of the data set, it is the default header. ‘report-column-header’ : defines the column header. SPACING= horizontal positions : Specifies how many blank characters to leave between the selected column and the column immediately to its left. The default is 2.
  16. 16. Defining Column Attributes 1. Add format to display height and weight with decimals. 2. Increase the column widths 3. Increase the spacing 4. Change column headings proc report data=mylib.fitness nowd; column patid gender age height_cm weight_kg; define patid/'Patient ID'; define height_cm / format =6.2 width=11 spacing=5 'Height (cm)'; define weight_kg / format=5.2 width=11 spacing=5 'Weight (kg)'; run;
  17. 17. Defining Column Attributes SAS Listing Output SAS HTML Output Note: Width and spacing attributes in the Define statement has no effect on HTML output.
  18. 18. Splitting Column Headings across Multiple Lines To split character, • Use the default slash (/) as the split character. • Define a split character by using the SPLIT= option in the PROC REPORT statement. proc report data=mylib.fitness nowd; column patid gender age height_cm weight_kg; define patid/'Patient ID'; define height_cm / format =6.2 width=6 spacing=5 'Height/(cm)'; define weight_kg / format=5.2 width=6 spacing=5 'Weight/(kg)'; run;
  19. 19. Splitting Column Headings across Multiple Lines SAS Output:
  20. 20. Specifying Column Justification To specify justification, add option CENTER, LEFT, or RIGHT in the DEFINE statement. proc report data=mylib.fitness nowd split='*'; column patid gender age height_cm weight_kg; define patid/'Patient ID' left; define age/ center; define height_cm / format =6.2 width=6 spacing=5 'Height*(cm)' center; define weight_kg / format=5.2 width=6 spacing=5 'Weight*(kg)' center; run;
  21. 21. Specifying Column Justification SAS Output:
  22. 22. Enhancing the Heading’s Appearance • HEADLINE : underlines all column headings and the spaces between them. • HEADSKIP : writes a blank line beneath all column headings or after the underline if the HEADLINE option is used. These options have no effect on HTML output. proc report data=mylib.fitness nowd headline headskip; column patid gender age height_cm weight_kg; define patid/'Patient ID'; define height_cm / format =6.2 width=6 spacing=5 'Height/(cm)'; define weight_kg / format=5.2 width=6 spacing=5 'Weight/(kg)'; run;
  23. 23. Enhancing the Heading’s Appearance SAS Output:
  24. 24. Variable Usage PROC REPORT uses each variable in one of six ways, • DISPLAY • ORDER • GROUP • ACROSS • ANALYSIS • COMPUTED By default, PROC REPORT uses, • character variables as display variables • numeric variables as analysis variables, which are used to calculate the SUM (default) statistic.
  25. 25. Defining Order Variables ORDER : orders the rows in the report. • Orders the report in ascending (default) order. Include the DESCENDING option in the DEFINE statement to force the order to be descending. • Suppresses repetitious printing of values. • Does not need data to be previously sorted. proc report data=mylib.fitness nowd ; column gender patid age height_cm weight_kg smoking race; define gender/order width=6; define patid/ 'Patient ID' width=10 left; define age/ width=3 center; define height_cm / format =6.2 width=11 spacing=5 'Height/(cm)' center; define weight_kg / format=5.2 width=11 spacing=5 'Weight/(kg)' center; run;
  26. 26. Defining Order variables SAS Output: Displays the data in order by Gender.
  27. 27. Defining Group Variables  Use the REPORT procedure to create a summary report by defining variables as group variables.  To define a group variable, specify the GROUP usage option in the DEFINE statement.  All observations whose group variables have the same values are collapsed into a single row in the report.  You can define more than one variable as a group variable.  Nesting of group variables is determined by the order of the variables in the COLUMN statement.  If you have a group variable, there must be no display or order variables.  Group variables produce summary reports (observations collapsed into groups).  Display and order variables produce listing reports(one row for each observation).
  28. 28. Defining Group Variables proc report data=mylib.fitness nowd ; column gender smoking weight_kg ; define gender/group width=6; define smoking/group width=7; define weight_kg / format=5.2 width=11 'Weight/(kg)' center; run; SAS Output Displays the total weight gender wise and smoking habit wise Note: The default statistic for the analysis variables is SUM.
  29. 29. Defining Analysis Variables • The default statistic for analysis variables is SUM. • To specify a statistic other than SUM (default), specify the statistic as an attribute in the DEFINE statement • Below are the few statistics that can be used in Proc Report; N Number of nonmissing values MEAN Average value MIN Minimum value MAX Maximum value STD Standard Deviation
  30. 30. Defining Analysis Variables proc report data=mylib.fitness nowd ; column gender smoking height_cm weight_kg; define gender/group width=6; define smoking/group width=7; define height_cm / mean format =6.2 width=19 spacing=5 'Average Height/(cm)' center; define weight_kg / mean format=5.2 width=19 spacing=5 'Average Weight/(kg)' center; run; SAS Output
  31. 31. Defining Across Variables • Variables can also be defined as Across variables which are functionally similar to group variables. However, PROC REPORT displays the groups that it creates for an across variable horizontally rather than vertically. proc report data=mylib.fitness nowd ; column gender smoking height_cm weight_kg; define gender/across width=6; define smoking/across width=7; define height_cm / mean format =6.2 width=19 spacing=5 'Average Height/(cm)' center; define weight_kg / mean format=5.2 width=19 spacing=5 'Average Weight/(kg)' center; run;
  32. 32. Defining Across Variables SAS Output: Notes: • For each across variable, the table cells contain a frequency count for each unique value. • For each analysis variable, the table cells represent the sum of all the variable's values.
  33. 33. Defining Computed Variables  Computed variables are the new variables that you define for the report. They are not present in the input dataset.  Computed variables can be either numeric or character variables.  You cannot change the usage of a computed variable.  To add a computed variable in Proc Report, • Include the computed variable in the COLUMN statement. • Define the variable's usage as COMPUTED in the DEFINE statement. • Compute the value of the variable in a compute block that is associated with the variable.  The position of a computed variable is very important. You can't base the calculation of a computed variable on any variable that appears to its right in the report. So in COLUMN statement specify the computed variable to the right of the variables that are used in its calculation.
  34. 34. Defining Computed Variables proc report data=mylib.fitness nowd ; column first_name last_name gender race age smoking weight_kg height_cm bmi; define first_name/'First Name' width=10; define last_name/'Last Name' width=9; define smoking/width=7; define height_cm / format =6.2 width=6 'Height (cm)'; define weight_kg / format=5.2 width=6 'Weight (kg)'; define bmi / computed 'Body Mass Index' format=5.2 width=15; compute bmi; bmi= weight_kg.sum/(height_cm.sum*0.01)**2; endcomp; run; Computed variable
  35. 35. Defining Computed Variables SAS Output: Computes the variable Body Mass Index using weight and height data.
  36. 36. Thank You !

×