Reputation: 4006
I'm looking for a way to split a very long string using this delimiter : '| '
The scan function doesn't seem to accept word delimiter so if I do
scan(string,3,'| ')
it will split at every |
and space
instead of at every '| '
like I need.
In the documentation I don't see any modifier allowing this. http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm
Upvotes: 1
Views: 6090
Reputation: 9109
INFILE has DLMSTR when combined with infile magic can do exactly what you need. Your transwrd idea should work well.
data test;
input string $50.;
cards4;
This|is | pipe space| delmimited
This| is| too I believe
;;;;
run;
data test2;
infile cards missover dlmstr='| ';
if _n_ eq 1 then input @;
array w[5] $64;
do while(not eof);
set test end=eof;
_infile_ = string;
input @1 w[*] @;
output;
end;
stop;
cards;
Necessary evil
run;
Upvotes: 3
Reputation: 4006
I found it out by myself
use tranwrd
to replace '| '
by '_'
newstring=tranwrd(string,'| ','_');
and then I can use the scan function normally
xxx=scan(newstringstring,3,'_');
Upvotes: 1