The SAS Output Delivery System and reporting techniques

PROC REPORT Order variables

Reply
Contributor
Posts: 20

PROC REPORT Order variables

Hi - when you specify a column as either 'Order' or 'Group', is there an option on the DEFINE statement to have the values repeat for every line, instead of once at the start of the group?

Respected Advisor
Posts: 3,768

Re: PROC REPORT Order variables

Here is how I do it, which is probably wrong.

proc report data=sashelp.class nowd list;
  
columns sex s name;
   define sex / order noprint;
  
define s / computed width=3 'Sex';
  
define name / display;
  
break after sex / skip; *skip does not work with ODS;
  
compute after sex;
      line ' ';
     
endcomp;
  
compute s / length=3;
      s = savesex;
     
endcomp;
  
compute before sex;
      savesex = sex;
     
endcomp;
  
run;
Contributor
Posts: 20

Re: PROC REPORT Order variables

Thanks!  I am surprised that there is not an easy option for the DEFINE statement for this.  Using compute blocks seems a bit clunky...

Respected Advisor
Posts: 3,768

Re: PROC REPORT Order variables

Like I said it may be wrong.

SAS Super FREQ
Posts: 8,645

Re: PROC REPORT Order variables

Hi:

  You are exactly correct. There is NOT an option on the DEFINE statement to have an ORDER or GROUP variable repeat on every row. The PROC REPORT "suppression" behavior is by design. Having only the first of the group appear and and having the other rows blank is the way that ORDER and GROUP have always behaved. So, if you want the value to repeat on every row, you have to essentially save the first value of the group into a temporary variable, then make a computed variable to hold the value on every row and give it the value of the temporary variable. Then you use NOPRINT on the "true" ORDER or GROUP variable.

     
  Your example was great. Starting in SAS 9.2, there was a new option, SPANROWS that makes ORDER or GROUP items have spanning rows (like TABULATE). Check this out (with ODS). The row area for SEX now spans the rows for NAME.

  

  The only change I made was to take out the BREAK AFTER statement. Sometime between ODS in SAS 7 and SAS 9, you can do a COMPUTE AFTER on an ORDER or GROUP variable without necessarily needing a BREAK, especially if all you want is the LINE from the COMPUTE. You would need the BREAK for SUMMARIZE, though.

    
  So, nice job.

   
cynthia

                           
ods html file='c:\temp\spanrows.html';

proc report data=sashelp.class nowd list spanrows;

   columns sex name;

   define sex / order;

   define name / display;

   compute after sex;

      line ' ';

   endcomp;

run;

ods html close;

Post a Question
Discussion Stats
  • 4 replies
  • 157 views
  • 0 likes
  • 3 in conversation