Returns the number of times a string appears in another string.
TALLY(x,y)
x and y are string expressions that must have computational type and should be character or bit.
TALLY returns the number of times the string x appears in the string y. The result is a Fixed Binary (31,0) value. If y does not appear in x, the result is zero. If any of these two expressions is a null string, the result is zero.
dcl s char (40); dcl n fixed bin (15); s = 'peter piper picked a peck of pickled peppers.'; n = tally(s, 'p'); put skip list ("'p' appears " || trim(n) || ' times.'); n = tally(s, 'pe'); put skip list ("'pe' appears " || trim(n) || ' times.'); n = tally(s, 'pi'); put skip list ("'pi' appears " || trim(n) || ' times.'); n = tally(s, 'ck'); put skip list ("'ck' appears " || trim(n) || ' times.');
will print:
'p' appears 8 times. 'pe' appears 4 times. 'pi' appears 3 times. 'ck' appears 3 times.
None.