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-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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
  • 189 views
  • 1 like
  • 2 in conversation