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

Hi all

I have some values containing text which can be in single or double quote marks. I would like to remove the quote marks plus the text inside

e.g.

 

have:

VAR1

hello "dog" is my pet

just text

hi 'people' how are you

 

want:

VAR1

hello is my pet

just text

hi how are you

 

thanks for your help

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

One way

 

data have;
input var1 $ 1 - 25;
datalines;
hello "dog" is my pet   
just text               
hi 'people' how are you 
;

data want;
   set have;
   var1 = compbl(prxchange('s/".*"//', -1, prxchange("s/'.*'//", -1, var1)));
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

One way

 

data have;
input var1 $ 1 - 25;
datalines;
hello "dog" is my pet   
just text               
hi 'people' how are you 
;

data want;
   set have;
   var1 = compbl(prxchange('s/".*"//', -1, prxchange("s/'.*'//", -1, var1)));
run;
kalbo
Obsidian | Level 7

Thanks for helping..it works perfectly

Ksharp
Super User

Peter.C

If there were multiple quote characters, your code would get wrong result.

Like this sort of data.

 

data have;
input var1 $ 1 - 40;
datalines;
hello "dog" is my pet "dog" xxx
just text
hi 'people' how are you 'people'
; data want; set have; var1 =prxchange("s/'.*?'|"".*?""//", -1, var1); run;

 

 

Ksharp
Super User
data have;
input var1 $ 1 - 40;
datalines;
hello "dog" is my pet "dog" xxx 
just text               
hi 'people' how are you 'people'  
;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 717 views
  • 1 like
  • 3 in conversation