BookmarkSubscribeRSS Feed
Michela_sas
SAS Employee
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
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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
Michela_sas
SAS Employee
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

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!

How to Concatenate Values

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.

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
  • 2 replies
  • 3282 views
  • 0 likes
  • 2 in conversation