As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Tip of the Day:November 8

From sasCommunity
Jump to: navigation, search

sasCommunity Tip of the Day

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.



Feel free to comment on this tip.


Prior tip - Next tip - Random Tip

Submit a Tip