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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.