/*
Breaks up a data string into a stem variable, using
a specified delimiter.
split_into_stem(delimiter, text, stem.)
delimiter = The pattern at which to break apart the data
text = The data string to break up. Must be a simple
or compound variable, not a stem.
stem. = The stem variable where the data is stored.
stem.0 will be set to the number of items, and
stem.1 to stem.X are those items.
Copyright Michael Simpson 2005
*/USEARG delimiter, text, stem.
DROP stem.
/* Assume one piece will be broken off */
i = 1
DOFOREVER/* Break off the next piece into "stem.i", and restore the remaining data in "text" */PARSEVAR text stem.i (delimiter) text
/* Did we break anything off? */IF stem.i == ""THENDO/* No, we didn't. So "text" is the last piece */IF text = ""THEN
i = i - 1 /* If nothing left, then don't count this last, empty piece */ELSE
stem.i = text /* Store the last piece *//* All done. End the loop */SIGNAL done
END/* Assume another piece will be broken off */
i = i + 1
END
done:
/* Save the count */
stem.0 = i
RETURN