Skip to content

Instantly share code, notes, and snippets.

@rpardee
Created November 21, 2013 17:35
Show Gist options
  • Save rpardee/7586054 to your computer and use it in GitHub Desktop.
Save rpardee/7586054 to your computer and use it in GitHub Desktop.
regex solution to a sas-l problem.
data have;
retain prx ;
input path : $800.;
if _n_ = 1 then do ;
prx = prxparse("(Sect1.2.3b|Sect1.1.a|Sect2.3.b|Sect3.3.2c)") ;
end ;
flg = (prxmatch(prx, path) > 0) ;
if flg then do ;
call prxsubstr(prx, path, pos, len) ;
excerpt = substr(path, pos, len) ;
end ;
drop pos len ;
datalines;
Garbage.Text.1/Garbage.Text.2/Sect1.2.3b/Garbage.Text.3
Garbage.Text.1/Sect1.1.a/Garbage.Text.2/Garbage.Text.4/Garbage.Text.5
Garbage.Text.1/Garbage.Text.2
Sect2.3.b/Garbage.Text.1
Garbage.Text.1/Garbage.Text.2/Garbage.Text.4/Garbage.Text.5/Sect3.3.2c
Garbage.Text.1/Garbage.Text.2/Garbage.Text.4/Garbage.Text.5
;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment