BookmarkSubscribeRSS Feed
mjaitly
Fluorite | Level 6

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

'

5 REPLIES 5
jakarman
Barite | Level 11

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 --<-----
Loko
Barite | Level 11

Hello,

One solution:

data have;

a='["Mumbai"]';

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

run;

stat_sas
Ammonite | Level 13

data have;

a='["Mumbai"]';

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

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

run;

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 .

Tom
Super User Tom
Super User

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'

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 2594 views
  • 0 likes
  • 6 in conversation