Tips:Anyspace function: search for the carriage return
From sasCommunity
DATA DEMONSTRATION; LENGTH WORD_LIST $ 55; INPUT WORD_LIST $ 1-55 @; LEN = LENGTH(WORD_LIST); LOCATION = ANYSPACE(WORD_LIST,-LEN); PUT LOCATION = LEN=; DATALINES; MURPHYISDEMONSTRATINGTHEREISNOSPACE MURPHYISDEMONSTRATING THESPACEINTHISSENTENCE MURPHYISDEMONSTRATINGTHETAB INTHISSENTENCE ; RUN;
Occasionally, carriage returns and other type blank space values get into the data fields. Sometimes, it is not easy to spot them in the data. However, there is an interesting function in SAS called ANYSPACE which can be used to detect such characters.
The documentation incorrectly states that ANYSPACE returns a 0 when a blank is not detected. To return a 0 when no space is found, you must search from the right. This is done by using a negative value as the second argument.
The LOG shows:
LOCATION=0 LEN=35 LOCATION=22 LEN=44 LOCATION=28 LEN=42
Submitted by Murphy Choy. Contact me at my Discussion Page.
....see also
