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.
@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.
Use the COMPRESS function
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.
@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.
You can use the compress() function to do that. The syntax below should help clean up the fields, hope this helps!
newvar=compress(oldvar,'"');
Alternatively try the perl regular expression function
data have;
input string$20.;
string2=prxchange('s/\"//',-1,string);
cards;
"0.1%"
"0.00123321%"
;
Thanks,
Jag
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.