Skip to content

Instantly share code, notes, and snippets.

@adam-garcia
Last active March 29, 2017 18:19
Show Gist options
  • Save adam-garcia/27909ded20c7915970d97411696cfe23 to your computer and use it in GitHub Desktop.
Save adam-garcia/27909ded20c7915970d97411696cfe23 to your computer and use it in GitHub Desktop.
Helpful SAS Snippets
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
** *
** extract_numeric.sas *
** purpose: extract numeric component from string *
** todo: leading strings break pattern *
** *
`* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
data strings;
input str $1-11;
put str;
datalines;
125
0.4 foo
.1 bar
100.111 baz
1 Hello,
12345 world
success 100
run;
data numbers;
set strings;
if _n_ eq 1 then do;
re = prxparse("/(\d*)(\.*)(\d+)/");
end;
retain re;
call prxsubstr(re, str, start, length);
if start gt 0 then num = input(substrn(str, start, length), best32.);
put num;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment