I have a dataset that will be sent to ods rtf output. I want to compare the dataset with mine, Some variables have characters that are used to create white space or 'ESC" for reporting. I am not sure how to remove them. I tried to compress and translate functions to manipulate. but I am having difficulty removing them."(*ESC*)R'\par '" is the extra string that I want to remove. When I used to compress it removing breakers (parenthesis) for others. How I can achieve this? Thank you for your suggestions. Also what exactly does this String (*ESC*)R'\par ') do?
data chk;
have = "55 (43.8%)(*ESC*)R'\par '92";
want = "55(43.8%)92";
run;
One way:
data chk; have = "55 (43.8%)(*ESC*)R'\par '92"; want = compress(tranwrd(have,"(*ESC*)R'\par '",'')); run;
The Tranwrd function replaces a whole matching string with another, in this case empty string (space) and Compress removes the spaces. TRANSLATE does a character by character replacement and would not be desired because if you replace the ( or the ) then the parentheses around the percentage also get replaced (I guess you found that out).
That \par would be RAW RTF codes, likely involving a paragraph (this is a guess, do a google search for "RTF Codes" for details) somewhere. The "*ESC*" part places an escape to allow the SAS ODS generator to send a raw rtf formatting code to a word processor that can handle them.
One way:
data chk; have = "55 (43.8%)(*ESC*)R'\par '92"; want = compress(tranwrd(have,"(*ESC*)R'\par '",'')); run;
The Tranwrd function replaces a whole matching string with another, in this case empty string (space) and Compress removes the spaces. TRANSLATE does a character by character replacement and would not be desired because if you replace the ( or the ) then the parentheses around the percentage also get replaced (I guess you found that out).
That \par would be RAW RTF codes, likely involving a paragraph (this is a guess, do a google search for "RTF Codes" for details) somewhere. The "*ESC*" part places an escape to allow the SAS ODS generator to send a raw rtf formatting code to a word processor that can handle them.
It worked. Thank you very much.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.