Help using Base SAS procedures

Proc Tabulate - Indent *Selected* Rows

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Proc Tabulate - Indent *Selected* Rows

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


Accepted Solutions
Solution
‎05-09-2013 06:20 PM
SAS Super FREQ
Posts: 8,868

Re: Proc Tabulate - Indent *Selected* Rows

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


All Replies
Super User
Posts: 11,343

Re: Proc Tabulate - Indent *Selected* Rows

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

Super User
Posts: 5,516

Re: Proc Tabulate - Indent *Selected* Rows

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.

Super User
Posts: 11,343

Re: Proc Tabulate - Indent *Selected* Rows

Posted in reply to Astounding

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 ...

Super User
Super User
Posts: 7,076

Re: Proc Tabulate - Indent *Selected* Rows

Posted in reply to Astounding

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.

Solution
‎05-09-2013 06:20 PM
SAS Super FREQ
Posts: 8,868

Re: Proc Tabulate - Indent *Selected* Rows

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;

Contributor
Posts: 28

Re: Proc Tabulate - Indent *Selected* Rows

Posted in reply to Cynthia_sas

Thank you all for your perspective. I really appreciate it

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1288 views
  • 7 likes
  • 5 in conversation