The ordering pattern for GROUP, ORDER, and ACROSS variables in PROC REPORT is established as the order of appearance across all observations in the data set when you specify the ORDER=DATA option in a DEFINE statement.
The REPORT procedure does not take any other variable into account when it establishes the ordering pattern. It ignores other GROUP, ORDER, or ACROSS variables and BY variables. Only the variable that is defined with the ORDER=DATA option is used to determine the sort order.
The ordering pattern is not changed for each group. For some reports with multiple GROUP, ORDER, or ACROSS variables, the output might not appear to be in the same order as the input data set. The sample code below demonstrates this behavior.
data test;
input var1 $ var2 $;
datalines;
A 1
A 4
B 1
B 2
B 99
D 1
D 2
D 3
D 4
D 99
;
run;
proc report data=test nowd;
column var1 var2;
define var1 / order order=data;
define var2 / order order=data;
run;
In this data set, the VAR2 values appear in this order: 1, 4, 2, 99, 3. The output reflects the ordering pattern based on all observations in the data set:
var1 var2
A 1
4
B 1
2
99
D 1
4
2
99
3
The order of the VAR2 values in the data set where VAR1=D might not appear as expected because the order of VAR2 is 1, 2, 3, 4, 99.
To achieve the desired order of VAR2 within VAR1 from the data set, create a counter in a DATA step prior to the PROC REPORT step. Place the counter variable before the variable of interest in the COLUMN statement. Define the counter variable as ORDER or GROUP with the NOPRINT option. See the sample code below.
data test2;
set test;
by var1 notsorted var2 notsorted;
retain cnt;
if first.var1 then cnt=0;
cnt+1;
run;
proc report data=test2 nowd;
column var1 cnt var2;
define var1 / order order=data;
define cnt / order order=internal noprint;
define var2 / order order=data;
run;
var1 var2
A 1
4
B 1
2
99
D 1
2
3
4
99
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.