The SAS Output Delivery System and reporting techniques

Tab separator escape character

Reply
SAS Employee
Posts: 11

Tab separator escape character

Hi!

I would like to use an escape character that allows me to separate two or more variables by a tab separator within the same cell of a PROC REPORT in ODS PDF.

I succeeded having them on different row using the ~n escape character, but I couldn't find anywhere the corresponding one for the tab separator.

Anybody has a suggestion?

Thank you!
Best regards.
Michela
SAS Super FREQ
Posts: 8,861

Re: Tab separator escape character

Posted in reply to Michela_sas
Hi:
Perhaps if there is a UNICODE character for TAB, there will be a way to insert it into PDF when 9.2 has the UNICODE function that you can use with ESCAPECHAR.

In the meantime, I only know of two ways to insert spaces into a cell. If the destination is RTF, you can use the \tab RTF control string (which has nothing to do with ODS ESCAPECHAR) OR you can use ODS ESCAPECHAR + underscore to insert a non-breaking space into either RTF or PDF.

[pre]
data testit;
length var1 var2 $100;
var1 = 'supercalifragilisticexpealidocious';
var2=var1;
output
var1 = 'one fish \tab \tab two fish';
var2 = 'red fish ~_~_~_~_~_~_~_~_~_ blue fish';
output;
run;

ods rtf file='c:\temp\tab.rtf';
ods pdf file='c:\temp\tab.pdf';
ods escapechar='~';

proc report data=testit nowd
style(column)={protectspecialchar=off};
column var1 var2;
define var1 /display;
define var2 /display;
run;
ods _all_ close;
[/pre]

The long word for the first obs will just let you count how many "characters" have been inserted with each method. Also, you need protectspecialchars=off for the \tab RTF control string -- you don't need it for the non-breaking space method -- but it's not hurting.

The down side of this method comes when you do something like this:
[pre]
newvar2 = trim(name)||'~_~_~_~_~_'||trim(city);
or
newvar2 = name||'~_~_~_~_~_'||trim(city);
[/pre]

in order to get your two variables in the same cell, they may not look lined up the way they would with a tab character. In a proportional space font, the second var might look a little "wavy" or not lined up because the letter 'i' in a proportional font takes up less space than a letter 'w'. So if names were Bob and Ila and the cities were Avon and Dale and you used code as shown above, then newvar2 would look like this if you trimmed the name (dots taking the place of the non-breaking space):
Bob..........Avon
Ila..........Dale

Also, when you use the non-breaking space method, if you do not want the text in the cell to break at all, you might consider replacing all internal spaces with the non-breaking space so SAS and ODS treat the 2 variables as one unbroken string (if the variables contain space characters):
var2 = 'red~_fish ~_~_~_~_~_~_~_~_~_ blue~_fish';

(or make the cellwidth wide enough for the concatenated variables). The ASCII tab separator character is 09'x -- but I have not found that it can be inserted into a PDF output file and recognized as a TAB character. That's why I made the opening comment about the UNICODE equivalent of TAB -- the big unknown is whether PDF output would -use- a UNICODE TAB.

When I try to figure these things out, I take SAS out of the loop and then ask the question -- How does PDF handle a TAB character when you convert a word processing document to PDF? I looked for, but could not find, the explanation of what happens when you have a Word document with TABS and then convert that Word document to PDF with Adobe Acrobat or Adobe Distiller. Does the Word TAB character get converted to the right number of space characters?

So this is a long answer to a short question with another question at the end of it. For the short term, ODS ESCAPECHAR + underscore will give you a non-breaking space to allow you to put white space into a cell (between 2 strings or 2 variables).

Good luck,
cynthia
SAS Employee
Posts: 11

Re: Tab separator escape character

Posted in reply to Cynthia_sas
Thank you, excellent explanation!

I tried to find out too how the tab character gets converted by Acrobat Distiller, but so far I haven't found a precise answer...

Best regards.
Michela
Ask a Question
Discussion stats
  • 2 replies
  • 316 views
  • 0 likes
  • 2 in conversation