BookmarkSubscribeRSS Feed

By default, PROC REPORT suppresses repeated values of group variables. This is very handy most of the time, but it would be really nice to have an option to display the value of the group variable on every row. There is a simple workaround, but when you have many group variables you can easily end up with four or five compute blocks and a slew of duplicate variables.

 

Example Data:

 

data example;
  input chargrp $ numgrp chargrp2 $ value;
  datalines;
grpa 1 grpx 5
grpa 2 grpx 23
grpa 1 grpy 15
grpa 2 grpy 2
grpb 1 grpx 13
grpb 1 grpy 11
grpb 2 grpy 12
grpb 2 grpy 34
;
run;

 

Default Functionality:

 

proc report data=example;
  column chargrp numgrp chargrp2 value;
  define chargrp / group;
  define numgrp / group;
  define chargrp2 / group;
  define value / sum;
run;

 

mtnbikerjoshua_0-1674834910506.png

Current Workaround:

 

proc report data=example;
  column chargrp numgrp disp_numgrp chargrp2 value;
  define chargrp / group;
  define numgrp / group noprint;
  define disp_numgrp / "NUMGRP" computed;
  define chargrp2 / group;
  define value / sum;

  compute chargrp;
    if not missing(chargrp) then hold_chargrp = chargrp;
    else chargrp = hold_chargrp;
  endcomp;

  compute disp_numgrp;
    if not missing(numgrp) then hold_numgrp = numgrp;
    disp_numgrp = hold_numgrp;
  endcomp;
run;

 

mtnbikerjoshua_1-1674835162716.png

Desired Functionality:

 

proc report data=example repeatgroupval;
  column chargrp numgrp chargrp2 value;
  define chargrp / group;
  define numgrp / group;
  define chargrp2 / group;
  define value / sum;
run;

/* or */

proc report data=example;
  column chargrp numgrp chargrp2 value;
  define chargrp / group repeatval;
  define numgrp / group repeatval;
  define chargrp2 / group;
  define value / sum;
run;

 

 P.S. I'm surprised this hasn't been suggested already, but I couldn't find it anywhere. If it has already been suggested, feel free direct me to that post and mark this as a duplicate.