SCAN(string,n,delimiters): returns the nth word from the character string string, where words are delimited by the characters in delimiters.
It is used to extract words from a character value when the relative order of words is known, but their starting positions are not.
NewVar=SCAN(string,n<,delimiters>); -returns the nth ‘word’ in the string
When the SCAN function is used:
the length of the created variable is 200 bytes if it is not previously defined with a LENGTH statement
delimiters before the first word have no effect When the SCAN function is used,
any character or set of characters can serve as delimiters
two or more contiguous delimiters are treated as a single delimiter
if n is negative, SCAN selects the word in the character string starting from the end of string.
If you omit delimiters , default is blank . < ( + & ! $ * ) ; ^ - / , %
Results in Last returns to Blog
LAST_NAME = SCAN(NAME,-1,' '); /* Scans from the right */
Jeff W. Snoker (908)782-4382
Raymond Albert (732)235-4444
Steven J. Foster (201)567-9876
Jose Romerez (516)593-2377
PROC REPORT DATA=FIRST_LAST NOWD;
TITLE "Names and Phone Numbers in Alphabetical Order (by Last Name)";
COLUMNS NAME PHONE LAST_NAME;
DEFINE LAST_NAME / ORDER NOPRINT WIDTH=20;
DEFINE NAME / DISPLAY 'Name' LEFT WIDTH=20;
DEFINE PHONE / DISPLAY 'Phone Number' WIDTH=13 FORMAT=$13.;