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

Hi Experts,

 

I am trying to use prxparse to match a pattern

 

data c;

pattern=prxparse('/abc|bcd|esd/');

position =prxmatch(pattern,' abc fgg rrt);

run;

 now i have another table with column c1 as follows:

C1

abc

bcd

esd

 

so my question is here can we use column values directly into prxparse to define pattern

rather then manually typing each value.

 

 

My other concern is how to remove consecutive duplicate string in 

 lets say I have values as follows:

 

column1

steve steve is walking is walking

steve john steve john is walking

steve john steve john steve john

 

 

So i want mu output as

column1

Steve is walking

Steve John is walking

steve John

 

Please help me on this.

In case of more clarifications required please revert.

 

Regards,

Rohit

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

First question: build the pattern by concatenating words (hint: use string = catx("|", string, word) )

 

Second question:

 

data have;
input str :&$64.;
datalines;
steve steve is walking is walking
steve john steve john is walking
steve john steve john steve john
steve is is john steve
;

data want;
set have;
length oldStr newStr $64;
oldStr = str;
do i = 1 to 100;
    newStr = prxchange("s/(\b\w+\b)(.*)(\1\s*)/\1\2/io", -1, oldStr);
    if newStr = oldStr then leave;
    oldStr = newStr;
    end;
drop i oldStr;
run;

proc print; run;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

First question: build the pattern by concatenating words (hint: use string = catx("|", string, word) )

 

Second question:

 

data have;
input str :&$64.;
datalines;
steve steve is walking is walking
steve john steve john is walking
steve john steve john steve john
steve is is john steve
;

data want;
set have;
length oldStr newStr $64;
oldStr = str;
do i = 1 to 100;
    newStr = prxchange("s/(\b\w+\b)(.*)(\1\s*)/\1\2/io", -1, oldStr);
    if newStr = oldStr then leave;
    oldStr = newStr;
    end;
drop i oldStr;
run;

proc print; run;
PG
tomrvincent
Rhodochrosite | Level 12
use the scan function to go word by word, skipping duplicates.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 696 views
  • 0 likes
  • 3 in conversation