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.
2 Comments
My final data set has values which begin with ' { ' and I want this to be displayed in my final RTF file. but for some reason the final RTF file only displays the values without '{ '. Can you please help me understand why does SAS output the rft with no curly brackets
The curly bracket has a special meaning to RTF. It designates the start of a command, which should not be printed. However, that does not mean you cannot display them as plain text. You can use the PROTECTSPECIALCHARS style attribute on the column that contains the curly bracket to tell RTF to view them as plain text. You should then see them as part of the value in your final file.
data a;
length value $20;
input value $;
cards;
abcd
adga{
}dsflj
{sdlfj}
;
ods rtf file='test.rtf';
proc report data=a;
define value / style( column) = { protectspecialchars = on};
run;
ods rtf close;