How to avoid 6 common PROC REPORT errors

0

Like every SAS procedure, PROC REPORT generates error messages that are specific to that procedure.  Some of these errors are easier to understand and work around than others.  In this blog post, I show six of the trickiest errors, explain what might be causing the error, and give advice for how to circumvent it.

#1.  ACROSS variable not defined

proc report data=sashelp.class;
column sex, height;
run;

ERROR: There is more than one ANALYSIS usage associated with the column defined by the following elements.

A comma in the COLUMN statement indicates that you want a variable to be used as an ACROSS variable, i.e. one variable stacked on top of another.  This error will occur if your program doesn’t include a DEFINE statement with a usage of ACROSS.

Circumvention: Add a DEFINE statement for the ACROSS variable.

proc report data=sashelp.class;
column sex, height;
define sex /across;
run;

#2.  DISPLAY or GROUP variable needs its own column

proc report data=sashelp.class;
 column sex, height;
 define sex /across;
 define height /group;
run;

ERROR: A DISPLAY or GROUP variable above or below an ACROSS variable requires that there be an ORDER, GROUP, or DISPLAY variable in the report that is not above or below an ACROSS variable.

Often a report requires an ACROSS variable with a character and an analysis variable underneath it. PROC REPORT can create this report, but it has to have a DISPLAY or GROUP variable that is its own column.

Circumvention: Add a grouping variable and place it before the ACROSS variable on the COLUMN statement. The new variable can be defined as NOPRINT so that it will not be seen in the report.

data class;
 set sashelp.class;
 dummy=1;
proc report data=class;
 column dummy sex, height ;
 define dummy /group noprint;
 define sex /across;
 define height /group;
run;

#3.  Variable below ACROSS variable defined as DISPLAY

proc report data=sashelp.class;
 column age sex, height;
 define age /group;
 define sex /across;
 define height /display;
run;

ERROR: There is no statistic associated with XXXX.

This error message is generated when the only variable below an ACROSS variable is defined as DISPLAY.

Circumvention:  Change the DISPLAY variable to be GROUP or add the N statistic after the ACROSS grouping on the COLUMN statement.

proc report data=sashelp.class;
 column age sex, height;
 define age /group;
 define sex /across;
 define height /group;
run;

#4.  Multiple summary rows on the same variable or location

proc report data=sashelp.class;
 column sex sex=sex2 weight;
 define sex /group;
 define sex2 /group;
 break after sex /summarize;
 break after sex2 /summarize;
run;

ERROR: The BREAK variable XXXX is not one of the GROUP or ORDER variables.

PROC REPORT does not have the ability to have multiple summary rows on the same variable or location. You’ll receive this error message if you have used one variable twice on the COLUMN statement (once using an alias), defined it as GROUP or ORDER, and there is a BREAK statement for both the variable and its alias.

Circumvention: Create a new variable in a DATA step that is a copy of the variable and use the new variable on the COLUMN statement instead of an alias.

data class;
 set sashelp.class;
 sex2=sex;
proc report data=class;
 column sex sex2 weight;
 define sex /group;
 define sex2 /group;
 break after sex /summarize;
 break after sex2 /summarize;
run;

#5.  Two different usages for the same variable

proc report data=sashelp.class;
 column age sex name age=age2;
 define age /group;
 define sex /group;
 define age2 /display;
run;

ERROR: XXXX conflicts with earlier use of XXXX.

In some circumstances PROC REPORT will not let you have two different usages for the same variable. In the example above, the variable age cannot be both GROUP and DISPLAY. An alias is most useful when you have an analysis variable that you want multiple statistics for, such as mean, min, or max. However, you can use an alias on any type of variable, but you do have to be careful about the usage issue.

Circumvention: Create a new variable in a DATA step that is a copy of the variable. This way the new variable contains the same information but can be used in any way you choose in the PROC REPORT step.

data class;
 set sashelp.class;
 age2=age;
proc report data=class;
 column age sex name age2;
 define age /group;
 define sex /group;
 define age2 /display;
run;

#6.  No format specified for LINE statement variable

proc report data=sashelp.class;
 column sex name age;
 define sex /group noprint;
 compute before sex;
   line 'this is for gender group ' sex;
 endcomp;
run;

ERROR: XXXX must use a character format.

This error normally occurs when a character variable is used on a LINE statement, and no format is specified after it. On a LINE statement you must specify a format for each item (variable).

Circumvention: Add an appropriate format after the variable on the LINE statement.

proc report data=sashelp.class;
 column sex name age;
 define sex /group noprint;
 compute before sex;
   line 'this is for gender group ' sex $1.;
 endcomp;
run;

See the REPORT procedure documentation for details on each of these statements.

Share

About Author

Jane Eslinger

SAS Technical Support Analyst

Jane is a Technical Support Analyst at SAS Institute Inc., in Cary, NC. She supports the REPORT procedure, ODS, and other Base SAS procedures. Before she joined SAS, Jane worked as a statistical programmer in the social science and clinical research fields. She is a graduate of NC State University with a Bachelor of Science in Statistics.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top