Lesson 6: Common SAS Functions
This lesson will explain some of the common functions in SAS.
1. SUBSTR: Extract a portion of the text variable
SUBSTR is normally used to break up a long string of text into different pieces of information.
This dataset contains some of the subject codes used in a University. We are going to break them into subject (first 3 letters) and subject number (last 3 numbers).
Subject = Substr( Code, 1, 3);
Subject_no = Substr( Code, 4, 3);
The Substr function contains 3 arguments:
SUBSTR ( Variable, Start, Length )
Variable: The variable where the function will be applied on
Start: The starting position to begin reading the variable.
Length: Number of character to read
As you can see in our example, 'Subject' extracts the portion of the 'Code' variable from the 1st position to the 3rd position; while 'Subject_no' extracts the portion from the 4th position to the 6th position.
DONE! You have learned the SUBSTR function in SAS!