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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: