Hello,
Before when I used to create my output using the traditional SAS monospace output, the blank spaces to the left were preserved and the line breaks were created, and my AE output was similar to the output below. I've now converted my outputs to RTF, and now the output in the report (for the column of interest) is either to the left, to the right or in the center. Can you please let me know how I can add indents to my RTF output? Also can you please let me know how I can also add the line breaks into the output too? Please see below for the example dataset and code.
MedDRA System Organ Class
Preferred Term
CTCAE Grade
-------------------------------------------------------------------------------------------
ANY SYSTEM / ANY TERM
Total (3 + 4 + 5)
3
4
5
BLOOD AND LYMPHATIC SYSTEM DISORDERS
Neutropenia
Total (3 + 4 + 5)
3
4
5
data test;
input @1 mycat $40. ptermord;
cards;
ANY SYSTEM / ANY TERM 1
Total (3 + 4 + 5) 1
3 1
4 1
5 1
BLOOD AND LYMPHATIC SYSTEM DISORDERS 2
Neutropenia 2
Total (3 + 4 + 5) 2
3 2
4 2
5 2
;
run;
* Creating indents *;
ods rtf file = "test.rtf";
data test2;
set test;
if _n_ in (2, 3, 4, 5, 8, 9, 10, 11) then mycat = " "||mycat;
run;
proc report data=test2 headline headskip split="¬" nowd missing style(report)=[whitespace=pre_wrap NOBREAKSPACE= OFF];
column MyCat ptermord;
define MyCat / display left width=73 format=$200. left flow id "MedDRA System Organ Class¬ Preferred Term¬ CTCAE Grade" style(column)=[cellwidth=75% WHITESPACE=PRE textalign = _UNDEF_];
define ptermord / order order=internal noprint;
break after ptermord / SKIP ;
run;
ods rtf close;
Many thanks in advance!
Hi: There are a few different ways to indent when you are using ODS RTF.
1) use INDENT= style override
2) use LEFTMARGIN= style override
3) use RTF control strings
Line breaks are the same:
1) use ODS ESCAPECHAR and the {NEWLINE} ESCAPECHAR function
2) use RTF control strings.
Some examples in the program below. More examples in this paper http://www2.sas.com/proceedings/forum2008/173-2008.pdf in example 1 and example 8.
Cynthia
ods listing close;
ods rtf file='c:\temp\indent_text.rtf' startpage=no;
ods escapechar='^';
proc report data=sashelp.class
style(report)={width=100%};
title 'showing indent and leftmargin';
define name / order 'The Header for Name^{newline 2}with a line break';
compute name;
if name = 'Alfred' or name = 'Janet' then do;
call define(_col_,'style','style={leftmargin=.50in}');
end;
else if name = 'Barbara' or name = 'John' then do;
call define(_col_,'style','style={indent=60}');
end;
endcomp;
compute after/style={just=l};
line 'This is an example of using ^{newline 1} a line break escapechar function within PROC REPORT';
endcomp;
run;
ods rtf close;
Hi: There are a few different ways to indent when you are using ODS RTF.
1) use INDENT= style override
2) use LEFTMARGIN= style override
3) use RTF control strings
Line breaks are the same:
1) use ODS ESCAPECHAR and the {NEWLINE} ESCAPECHAR function
2) use RTF control strings.
Some examples in the program below. More examples in this paper http://www2.sas.com/proceedings/forum2008/173-2008.pdf in example 1 and example 8.
Cynthia
ods listing close;
ods rtf file='c:\temp\indent_text.rtf' startpage=no;
ods escapechar='^';
proc report data=sashelp.class
style(report)={width=100%};
title 'showing indent and leftmargin';
define name / order 'The Header for Name^{newline 2}with a line break';
compute name;
if name = 'Alfred' or name = 'Janet' then do;
call define(_col_,'style','style={leftmargin=.50in}');
end;
else if name = 'Barbara' or name = 'John' then do;
call define(_col_,'style','style={indent=60}');
end;
endcomp;
compute after/style={just=l};
line 'This is an example of using ^{newline 1} a line break escapechar function within PROC REPORT';
endcomp;
run;
ods rtf close;
Thank you for this Cynthia, this works! 🙂
I was just wondering do you know if it's possible if I can add RTF control words to the dataset, and then produce the report using the RTF control words that are in the dataset? This is just because typically I have added the spaces/indents to the dataset that was used in Proc Report. If not it's fine and I will start producing the indents the way you suggested.
Thank you.
Hi:
The downside of the RTF control string approach is that you cannot, then, send the output to PDF or HTML without changing the data. I have had many students who went down the RTF control string approach, only to discover that, later, they needed to also produce the same report for a web page or for Acrobat Reader. If they had used ODS techniques that work in most destinations, then one program would have sufficed.
If you do insert the RTF control strings in the data, then you MUST turn the style attributes PROTECTSPECIALCHARS=OFF for the elements (probably DATA or HEADER) where you have added the strings. Otherwise, SAS and ODS might try to "protect" the special characters used in the control strings.
cynthia
Thank you Cynthia 🙂
4) use PRETEXT=' ' and ASIS=ON style override
5) use escapchar ~_~_~_~_ before the variable.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.