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;
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
  • 4505 views
  • 3 likes
  • 3 in conversation