*Copyright @ www.mycsg.in;


What is a function in SAS

What is a character function

Character functions that change case

Function Definition
UPCASE Converts letters in a character string to uppercase.
LOWCASE Converts letters in a character string to lowercase.
PROPCASE Converts text to proper case by capitalising the first letter of each word and lowercasing the remaining letters.

Create sample data

Create upper, lower, and proper case versions of the string variable

Character functions that return string length

Function Definition
LENGTH Returns the number of characters excluding trailing blanks and returns 1 for a blank string.
LENGTHN Returns the number of characters excluding trailing blanks and returns 0 for a blank string.

Create sample data

Compare LENGTH and LENGTHN

Use SCAN to extract words from a string

Function Definition
SCAN Extracts a word from a string based on word position and delimiters.

Create sample data

Extract words using SCAN

Use SUBSTR to extract or modify part of a string

Function Definition
SUBSTR Extracts part of a string and can also be used on the left side of an assignment to replace part of a string.

Create sample data

Extract and modify parts of a string using SUBSTR

Use FIND to locate a substring

Function Definition
FIND Returns the position of the first occurrence of a substring within a string.

Create sample data

Use FIND to locate text in a string

Key points to remember