BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AntoineA
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Use the COMPRESS function

--
Paige Miller
AntoineA
Fluorite | Level 6

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
dcruik
Lapis Lazuli | Level 10

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

 

newvar=compress(oldvar,'"');

Jagadishkatam
Amethyst | Level 16

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
Patrick
Opal | Level 21

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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