Usage Note 24542: When I specify ORDER=DATA in the DEFINE statement, I do not get the exact order of the input data set in my report. How can I get the desired ordering of my data?
When ORDER=DATA is specified, PROC REPORT orders the GROUP/ORDER/ACROSS
variable in order of appearance across all observations in the data set, not per grouping. If all the values in the variable are not in the first grouping, PROC REPORT establishes an ordering pattern based on the first grouping. For each subsequent grouping, any new value is added to the end of the established ordering pattern.
To achieve the desired order of the data from the data set, create a counter in the DATA step prior to the REPORT procedure. Use the counter as the first variable in the COLUMN statement, and define the variable as an ORDER or GROUP with a NOPRINT.
Here is an example of how to create a counter to achieve the desired order of the report data:
DATA test;
INPUT type $ num;
count +1;
DATALINES;
a 1
a 2
b 3
a 4
b 5
b 6
b 7
;
RUN;
DATA new;
SET test;
RETAIN hold ' ';
IF _n_=1 THEN DO;
hold=type;
flag=1;
END;
IF hold NE type THEN DO;
hold = type;
flag + 1;
END;
RUN;
OPTIONS NOCENTER;
PROC REPORT NOWD;
COL type num count;
DEFINE type / ORDER ORDER=DATA;
DEFINE num / ORDER ORDER=DATA;
TITLE 'PROC REPORT not in the ORDER of the DATA';
RUN;
PROC REPORT NOWD;
COL flag type num count;
DEFINE flag / ORDER ORDER=DATA NOPRINT;
DEFINE type / ORDER ORDER=DATA;
DEFINE num / ORDER ORDER=DATA;
TITLE 'PROC REPORT in the ORDER of the DATA';
RUN;
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.
| Type: | Usage Note |
| Priority: | low |
| Topic: | SAS Reference ==> Procedures ==> REPORT
|
| Date Modified: | 2007-12-17 10:47:13 |
| Date Created: | 2006-09-11 13:49:26 |