Dear community,
I am trying to subtract a specific group of words separated by dot.
The first word will always be LIB followed by a dataset name and a variable name. However, in the same description LIB can be present multiple times, but only once will have both dataset and variable name attached.
I've tried using PRX functions but without success.
data have;
length text $200;
infile datalines dsd;
input text;
datalines;
Random text LIB.XX_YYY.ZZZZZZZZ random text LIB.XX_YYY random text.
Random text LIB.AA random text LIB.AA.BB_BBB
LIB.XX3_X.YZYZYZ3
Random text LIB.AA1: random text LIB.AA1.ABCD, random text LIB.
;
run;
So from the above dataset I would like to keep in a variable: 'LIB.XX_YYY.ZZZZZZZZ' for first row, 'LIB.AA.BB_BBB' for the second row etc.
Thank you.
Get possibly multiple matches per string with prxNext:
data want;
if not prxId then prxId + prxParse("/LIB\.\w+\.\w+/");
set have;
start = 1; stop = length(text);
call prxnext(prxID, start, stop, text, position, length);
do while (position > 0);
word = substr(text, position, length);
output;
call prxnext(prxID, start, stop, text, position, length);
end;
drop start stop position length;
run;
Add if position=0 then output; after the first call to prxNext if you want some output for empty matches.
Please show what the exact desired output for the given data would be.
And you should provide a general rule. We cannot tell what the "etc" results would be because there is no general rule to apply.
The general rule is on each row to locate and keep in a new variable only the group of 3 words starting with LIB and having '.' as separator.
My desired output is:
keep |
|
|
|
|
Get possibly multiple matches per string with prxNext:
data want;
if not prxId then prxId + prxParse("/LIB\.\w+\.\w+/");
set have;
start = 1; stop = length(text);
call prxnext(prxID, start, stop, text, position, length);
do while (position > 0);
word = substr(text, position, length);
output;
call prxnext(prxID, start, stop, text, position, length);
end;
drop start stop position length;
run;
Add if position=0 then output; after the first call to prxNext if you want some output for empty matches.
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.