Skip to content
AgileLogics
7 min read

PROC FORMAT and PROC REPORT

Prerequisites: PROC FREQ

Custom formats

PROC FORMAT creates your own formats: labels for codes, or groups for ranges of values.

proc format;
   value agegrp
      low-12 = 'Pre-teen'
      13-high = 'Teen';
   value $sexfmt
      'F' = 'Female'
      'M' = 'Male';
run;

proc freq data=sashelp.class;
   tables age sex / nocum;
   format age agegrp. sex $sexfmt.;
run;
Age         Frequency     Percent
---------------------------------
Pre-teen           7       36.84
Teen              12       63.16

Sex         Frequency     Percent
---------------------------------
Female             9       47.37
Male              10       52.63
  • value defines a numeric format; value $name a character one.
  • Ranges use -, with low, high, and other as keywords. < excludes an endpoint: 0 -< 18 means "0 up to but not including 18".
  • Procedures group by the formatted value — a powerful way to regroup data without creating new variables.
  • Formats are saved in the WORK.FORMATS catalog; use proc format library=mylib; plus the FMTSEARCH option to keep them permanently.

Formats also make lookups: region = put(code, $regionfmt.); maps codes to names in a DATA step without a merge.

PROC REPORT

PROC REPORT builds custom tables — detail rows, group summaries, computed columns, and totals:

proc report data=sashelp.class;
   column sex n weight height;
   define sex / group format=$sexfmt. 'Sex';
   define n / 'Students';
   define weight / mean format=6.1 'Mean weight';
   define height / max format=5.1 'Tallest';
   rbreak after / summarize;
run;

Output (simplified):

Sex       Students  Mean weight  Tallest
Female           9         90.1     66.5
Male            10        109.0     72.0
                19        100.0     72.0
  • COLUMN lists the columns in order; n is a count.
  • DEFINE sets each column's role: group (one row per value), display (detail), analysis with a statistic (sum, mean, max), order, or computed.
  • rbreak after / summarize; adds a total row at the end, where each statistic is computed over all rows.
  • compute blocks add calculated columns and custom text.

Combined with ODS (Level 3), PROC REPORT produces the formatted tables used in clinical study reports and business reporting.

Practice

Create a format that labels weights under 90 as Light, 90 to under 110 as Medium, and 110 and over as Heavy, and count the students in each.

Show solution
proc format;
   value wtgrp
      low -< 90 = 'Light'
      90 -< 110 = 'Medium'
      110 - high = 'Heavy';
run;

proc freq data=sashelp.class;
   tables weight / nocum;
   format weight wtgrp.;
run;
Weight      Frequency     Percent
---------------------------------
Light              7       36.84
Medium             5       26.32
Heavy              7       36.84

What's next

Try the Intermediate Projects, then continue to Level 3 — Advanced: macros, ODS, statistical modeling, and SAS in production.