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

Hello.  What is the easiest way to:

 

  • remove the " character from a character variables values?
  • remove the ' character from a character variables values?

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

We need more information here. What exactly are we looking at? As @Reeza said, you can remove things with COMPRESS. This example shows how to only keep (k) alphabetical characters (a) and spaces (s).

 

data have;
x = 'This "is" a great string';
y = "This 'is' a great string";
run;

data want;
	set have;
		x_no_double = compress(x,,"kas");
		y_no_single = compress(x,,"kas");
run;

 

Obs x y x_no_double y_no_single
1 This "is" a great string This 'is' a great string This is a great string This is a great string

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User
COMPRESS() function to remove specific characters.

maguiremq
SAS Super FREQ

We need more information here. What exactly are we looking at? As @Reeza said, you can remove things with COMPRESS. This example shows how to only keep (k) alphabetical characters (a) and spaces (s).

 

data have;
x = 'This "is" a great string';
y = "This 'is' a great string";
run;

data want;
	set have;
		x_no_double = compress(x,,"kas");
		y_no_single = compress(x,,"kas");
run;

 

Obs x y x_no_double y_no_single
1 This "is" a great string This 'is' a great string This is a great string This is a great string

 

 

Reeza
Super User
So you have no other punctuation in your strings?

Try it with this as your input data and ensure it meets your needs.

data have;
x = 'This, "is" a great string!!';
y = "This 'is' a great-string!" ;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4556 views
  • 3 likes
  • 3 in conversation