Last active
March 29, 2017 18:19
-
-
Save adam-garcia/27909ded20c7915970d97411696cfe23 to your computer and use it in GitHub Desktop.
Helpful SAS Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
** * | |
** 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