BookmarkSubscribeRSS Feed
Petersi
Calcite | Level 5

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?

4 REPLIES 4
data_null__
Jade | Level 19

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;
Petersi
Calcite | Level 5

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

data_null__
Jade | Level 19

Like I said it may be wrong.

Cynthia_sas
SAS Super FREQ

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1041 views
  • 0 likes
  • 3 in conversation