BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

SASuserlot
Barite | Level 11

It worked. Thank you very much.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1097 views
  • 1 like
  • 2 in conversation