Help using Base SAS procedures

Tranwrd function

Reply
Occasional Contributor
Posts: 19

Tranwrd function

Hi

I need to remove [" from the word say ["Mumbai"]. I am able to remove the [ and ] using functions like Tranwrd however I want to know how to remove the " as the function syntax itself has an opening " and a closing " and I am unable to remove the " (which is itself a part of the input). SAS does not seem to be accepting the " within the opening " and closing ". I will appreciate any help.

Thanks

Manish

'

Valued Guide
Posts: 3,208

Re: Tranwrd function

When you need to remove characters, I would use the character functions not the word ones.  eg SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition  PRX (perl regular strings) are also an option. Within SAS the definition of a string is a basic concept but lost a clear reference. Single quotes (no macro expansion) double quotes (with macro expansion can be used to mark a string begin/end . Repeating a quote is masking the meaning.   See: SAS(R) 9.4 Language Reference: Concepts, Third Edition   example on Tom's     

---->-- ja karman --<-----
Super Contributor
Posts: 305

Re: Tranwrd function

Hello,

One solution:

data have;

a='["Mumbai"]';

b=compress(a,'"[]');

run;

Trusted Advisor
Posts: 1,204

Re: Tranwrd function

data have;

a='["Mumbai"]';

b=Tranwrd(a,'["','');

c=Tranwrd(b,'"]','');

run;

Occasional Contributor
Posts: 7

Re: Tranwrd function

hi mjaitly

you can use compress with the "keep" option to select all letters from the original text,

because you have capital letters as well I recommend the following syntax :

data have;

have='["New York"]';

need=compress(have,'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'K');

any_other_word='["or any other word"]';
any_other_word1=compress(any_other_word,'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'K');
run;

this way you can deal with capital letters and blanks you want to keep, and get rid of all other punctuations symbols .

Super User
Super User
Posts: 6,495

Re: Tranwrd function

If you want to include a quote inside of a quoted string you need to double up the quote character.  Note that you can also convert from using using double quotes to single quotes.

Examples:

" ""Mumbai"" "

' "Mumbai" '

"Don't"

'Don''t'

Ask a Question
Discussion stats
  • 5 replies
  • 469 views
  • 0 likes
  • 6 in conversation