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
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;
If the values have leading spaces you want displayed then add ASIS to the classlev style section for that variable.
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.
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 ...
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.
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;
Thank you all for your perspective. I really appreciate it
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.