SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Modifying Character Values with Functions


SCAN versus SUBSTR

The SCAN function has similarities to the SUBSTR function. Let's briefly compare the two. Both the SCAN and SUBSTR functions can extract a substring from a character value:

  • SCAN extracts words within a value that is marked by delimiters.

  • SUBSTR extracts a portion of a value by starting at a specified location.

The SUBSTR function is best used when you know the exact position of the substring to extract from the character value. The substring does not need to be marked by delimiters. For example, the first two characters of the variable ID identify the class level of college students. The position of these characters does not vary within the values of ID.

SAS Data
Name ID
Trentonson, Matthew Robert SO45467
Truell, Marcia Elizabeth SR32881


The SUBSTR function can extract this class-level information from ID. However, the SCAN function is best used when
  • you know the order of the words in the character value
  • the starting position of the words varies
  • the words are marked by some delimiter.


|next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement