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.

sas-innovate-white.png

Our biggest data and AI event of the year.

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.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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