BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
OPHD1
Fluorite | Level 6

I have been searching on the discussion boards and in documentation and can not find how to indent selected rows in PROC TABULATE, (e.g. not by using / indent =  since I would like to indent selected rows within a variable).

For example,

data orig_dat;

     infile datalines delimiter = ',';

     length Measure $ 12;

     input Measure $ Group $ Rate LCL UCL @@;

     datalines;

     Measure1,Group1,2345,1234,3456

     Measure1,Group2,3345,2234,4456

     Measure1,Group3,4345,3234,5456

     Measure2,Group1,234,123,456

     Measure2,Group2,345,234,456

     Measure2,Group3,456,345,678

     ;

run;

*for example, client asked for Measure2 indented;

data indent_selected (keep = measure_ind group rate lcl ucl);

     set orig_dat;

     length measure_ind $ 25;

     if measure = 'Measure1' then measure_ind = 'Measure1';

     if measure = 'Measure2' then measure_ind = '     Measure2';

run;

proc tabulate data=indent_selected order_data;

     class measure_ind;

     class group;

     var rate lcl ucl;

     table measure_ind = '  ',

          group = '  ' * (rate lcl ucl)*max = '  ' *f=DOLLAR8.;

run;

Proc Tabulate skips over the tab in the character variable and produces output of the form:

                         Group1                         Group2                    Group3

               Rate     LCL     UCL     Rate     LCL     UCL     Rate     LCL     UCL

Measure1

Measure2

I tried using spaces instead of a tab, and it produced the same result above.

However, when I used asterisks, just to test anything other than a tab or a space, it produced ****Measure2.

Any advice? Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  There is 1 way to do this with PROC TABULATE and 2 ways to do this with PROC REPORT. You do not need to "pad" the variable value with blanks or unprintable characters or make a copy of the data. In SAS 9.3 (and for some destinations, it was earlier), the INDENT= style attribute will work. Since the PROC FORMAT method works so well, you don't really need the CALL DEFINE method, I just included it because it is a viable alternative.
 

cynthia

data orig_dat;
     infile datalines delimiter = ',';
     length Measure $ 12;
     input Measure $ Group $ Rate LCL UCL @@;
     datalines;
     Measure1,Group1,2345,1234,3456
     Measure1,Group2,3345,2234,4456
     Measure1,Group3,4345,3234,5456
     Measure2,Group1,234,123,456
     Measure2,Group2,345,234,456
     Measure2,Group3,456,345,678
     ;
run;
  
proc format;
  value $measf 'Measure1' = '0in'
               'Measure2' = '.25in';
run;
  
ods listing close;
ods html file='c:\temp\indent_header.html' style=sasweb;
ods rtf file='c:\temp\indent_header.rtf';
ods pdf file='c:\temp\indent_header.pdf';
proc tabulate data=orig_dat;
  title '1) TABULATE with FORMAT';
     class measure group;
     classlev measure / style={indent=$measf. cellwidth=2in};
     var rate lcl ucl;
     table measure  = '  ',
          group = '  ' * (rate lcl ucl)*max = '  ' *f=DOLLAR8.;
run;
 
proc report data=orig_dat nowd;
    title '2a) Using PROC REPORT with Format';
    column measure group,(rate lcl ucl);
    define measure / group 
           style(column)=RowHeader{indent=$measf. cellwidth=2in};
    define group /across ' ';
    define rate / max;
    define lcl / max;
    define ucl / max;

run;
   
proc report data=orig_dat nowd;
    title '2b) Using PROC REPORT with CALL DEFINE';
    column measure group,(rate lcl ucl);
    define measure / group
           style(column)={cellwidth=2in};
    define group /across ' ';
    define rate / max;
    define lcl / max;
    define ucl / max;
    compute measure;
      if measure = 'Measure1' then
         call define(_col_,'style','style=RowHeader');
      else if measure = 'Measure2' then
         call define(_col_,'style','style=RowHeader{indent=.25in}');
    endcomp;
   run;
ods _all_ close;

View solution in original post

6 REPLIES 6
ballardw
Super User

If the values have leading spaces you want displayed then add ASIS to the classlev style section for that variable.

Astounding
PROC Star

Instead of adding blanks up front, add an unprintable character.  For example:

if measure='Measure2' then measure_ind='0101'x || 'Measure2';

You may have to fiddle to find the right character to use.  What is unprintable to one system may be printable on another.

Good luck.

ballardw
Super User

In Windows you can add a null character to implemetn Astounding's idea by pressing 255 while holding down the Alt key.

The fun part is it looks like a space in the editor so only you know what's going on ...

Tom
Super User Tom
Super User

I would use 'A0'x.  Windows has decided that this code is a "non-breaking space".  I have been seeing it more and more in source data (and on line posting) as a number of editors or web-based formatting tools are using it.

Cynthia_sas
SAS Super FREQ

Hi:

  There is 1 way to do this with PROC TABULATE and 2 ways to do this with PROC REPORT. You do not need to "pad" the variable value with blanks or unprintable characters or make a copy of the data. In SAS 9.3 (and for some destinations, it was earlier), the INDENT= style attribute will work. Since the PROC FORMAT method works so well, you don't really need the CALL DEFINE method, I just included it because it is a viable alternative.
 

cynthia

data orig_dat;
     infile datalines delimiter = ',';
     length Measure $ 12;
     input Measure $ Group $ Rate LCL UCL @@;
     datalines;
     Measure1,Group1,2345,1234,3456
     Measure1,Group2,3345,2234,4456
     Measure1,Group3,4345,3234,5456
     Measure2,Group1,234,123,456
     Measure2,Group2,345,234,456
     Measure2,Group3,456,345,678
     ;
run;
  
proc format;
  value $measf 'Measure1' = '0in'
               'Measure2' = '.25in';
run;
  
ods listing close;
ods html file='c:\temp\indent_header.html' style=sasweb;
ods rtf file='c:\temp\indent_header.rtf';
ods pdf file='c:\temp\indent_header.pdf';
proc tabulate data=orig_dat;
  title '1) TABULATE with FORMAT';
     class measure group;
     classlev measure / style={indent=$measf. cellwidth=2in};
     var rate lcl ucl;
     table measure  = '  ',
          group = '  ' * (rate lcl ucl)*max = '  ' *f=DOLLAR8.;
run;
 
proc report data=orig_dat nowd;
    title '2a) Using PROC REPORT with Format';
    column measure group,(rate lcl ucl);
    define measure / group 
           style(column)=RowHeader{indent=$measf. cellwidth=2in};
    define group /across ' ';
    define rate / max;
    define lcl / max;
    define ucl / max;

run;
   
proc report data=orig_dat nowd;
    title '2b) Using PROC REPORT with CALL DEFINE';
    column measure group,(rate lcl ucl);
    define measure / group
           style(column)={cellwidth=2in};
    define group /across ' ';
    define rate / max;
    define lcl / max;
    define ucl / max;
    compute measure;
      if measure = 'Measure1' then
         call define(_col_,'style','style=RowHeader');
      else if measure = 'Measure2' then
         call define(_col_,'style','style=RowHeader{indent=.25in}');
    endcomp;
   run;
ods _all_ close;

OPHD1
Fluorite | Level 6

Thank you all for your perspective. I really appreciate it

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 3494 views
  • 7 likes
  • 5 in conversation