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
Post a Comment