delimiter - SAS: Extract ID's separated by dashes from text string -


i have dataset has 1 concatenated text field. trying break 3 text columns in sas 9.4.

obs var1 1   may12-kansas-abcd6194-xy7199-brule 2   jan32-ohio-bz5752-gary 

my output observation 1 should this:

obs   date   state   id 1     may12  kansas  abcd6194-xy7199-brule 

here's have, works date , state. however, can't third part (id) ignore delimiter:

data have;    input var1 &$64.;    cards; may12-kansas-abcd6194-xy7199-brule jan32-ohio-bz5752-gary ; run; data need;    length id $16;    set have;    date = scan(var1,1,'-','o');    state = scan(var1,2,'-','o');    id = scan(var1,3,'-',''); run; 

another different approach multi-delimiter-containing word use call scan. tell position (and length, ignore) of nth word (and can forwards or backwards, gives ability search in middle of string).

implemented particular case it's simple:

data want;   set have;   length      date $5     state $20     id $50   ;   date = scan(var1,1);   state= scan(var1,2);   call scan(var1,3,position,length);   id = substr(var1,position); run; 

position , length variables call scan populates values can use. (we have done date , state way also, it's more work using function.)


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -