Data Have ;
input data $100. ;
cards ;
data/dataflow/BPS.STQR/EZR/1.0/RER_QWE_MED.D.AUD.MED, RER_QWA_MED.D.CAD.WOW.WOW.OF00, QWZ_PLO_WOW.D.POP
;
Run ;
Data Want ;
input x1 $60. ;
cards ;
RER_QWE_MED , RER_QWA_MED , QWZ_PLO_WOW
;
Run ;
Hello,
Seems like this can work for TYPE B,
Hello,
Seems like this can work for TYPE B,
@J111
You've got already a solution so below just for your consideration.
You wrote: "best solution would handle both type A and type B in the same row".
I made in below code the assumption that also type B should only select terms that only contain upper case letters and the underscore. If that's the case then you can "merge" your two type into a single rule.
Below should return your desired result based on my understanding of your rules.
Data Have ;
infile datalines4 truncover;
input source_string $600. ;
datalines4 ;
/availability/dataflow/*/*/*/*/-
data/dataflow/BPS.STQR/WAB/1.0/NER_PGTABC
/data/dataflow/BPS.STQR/EZR/1.0/RER_QWE_MED.D.AUD.MED.MED.OF00,RER_QWA_MED.D.CAD.WOW.WOW.OF00,QWZ_PLO_WOW.D.POP.WOW.MED.OF00
NOSLASH.AT.ALL
/SLASH_bUT_mIxed_Case.B.C
;;;;
Run;
data want(drop=_:);
set have;
/* substring after last forward slash if any, else just whole string */
_s=scan(source_string,-1,'/');
/* within _s iterate for each substring that ends with a comma or is the last substring */
do _i=1 to countc(_s,',')+1;
length _word $50 words $200;
/* extract the first sub-string that ends with a full stop else the whole string */
_word=scan(scan(_s,_i,','),1,'.');
/* check that _word only contains upper case characters or the underscore */
if prxmatch('/^[A-Z_]+$/',strip(_word))=1 then
do;
words=catx(',',words,_word);
end;
end;
if missing(words) then words='NOWORD';
run;
proc print data=want;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.