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
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;
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;
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!
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.