DATA Step, Macro, Functions and more

Removing quotation marks

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Removing quotation marks

Hi,

 

I have a simple question for you experts.

 

I have a dataset where all the data are between double quotation marks.

 

Exemple:

"0.1%" 

"0.00123321%"

and "" when there is no value.

 

How do I remove the quotations marks.

 

PS. I need to remove them in order to be able to do show descriptive statistics with the proc means function.

 

Thank you.


Accepted Solutions
Solution
‎10-20-2015 07:10 PM
Trusted Advisor
Posts: 1,911

Re: Removing quotation marks

[ Edited ]

AntoineA wrote:

Thank you both,

 

the compress command would not work for me the output data kept the "".

 



Try this:

 

newvariable=compress(oldvariable,'"');

 

That's a little hard to read, but after oldvariable, you type a comma, a single quote, a double quote and then another single quote. This removes the double-quotes from oldvariable, and creates newvariable without the double quotes.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,911

Re: Removing quotation marks

Use the COMPRESS function

New Contributor
Posts: 4

Re: Removing quotation marks

Posted in reply to PaigeMiller

Thank you both,

 

the compress command would not work for me the output data kept the "".

spread6m99=compress(spread6m,'"');
Instead I tried this:


spread6m99 = substr(spread6m,2,(length(spread6m)-3));
IF spread6m99='"' THEN spread6m99='';

 

seems to work.

Solution
‎10-20-2015 07:10 PM
Trusted Advisor
Posts: 1,911

Re: Removing quotation marks

[ Edited ]

AntoineA wrote:

Thank you both,

 

the compress command would not work for me the output data kept the "".

 



Try this:

 

newvariable=compress(oldvariable,'"');

 

That's a little hard to read, but after oldvariable, you type a comma, a single quote, a double quote and then another single quote. This removes the double-quotes from oldvariable, and creates newvariable without the double quotes.

Frequent Contributor
Posts: 130

Re: Removing quotation marks

[ Edited ]

You can use the compress() function to do that.  The syntax below should help clean up the fields, hope this helps!

 

newvar=compress(oldvar,'"');

Trusted Advisor
Posts: 1,137

Re: Removing quotation marks

Alternatively try the perl regular expression function

 

data have;
input string$20.;
string2=prxchange('s/\"//',-1,string);
cards;
"0.1%" 
"0.00123321%"
;

Thanks,

Jag

Thanks,
Jag
Respected Advisor
Posts: 4,173

Re: Removing quotation marks

[ Edited ]

How do you get to these strings in quotes in first place?

If it's you reading in some text file then these quotes could already get removed in this extract step.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 518 views
  • 3 likes
  • 5 in conversation