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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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