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

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!

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
  • 22931 views
  • 5 likes
  • 5 in conversation