Sentry Page Protection
SAS Functions [8-14]
LENGTH Function
You can use the LENGTH function to find out how many characters are there in a character value.
Let's take a look at the LIST data set.
The LIST data set contains a list of names.
[Reminder: To see the LIST data set on SAS Studio, run the code in the yellow box above]
Now, let's take a look at an example of the LENGTH function.
Example
Data List2;
Set List;
Len = Length(Name);
Run;
The LENGTH function created a new variable LEN, which shows the number of characters in each names.
Exercise
Copy and run the FIRSTNAME data set from the yellow box below.
Copy and run the FIRSTNAME data set from the yellow box below.
Write a SAS program to find out the length of each name.
Create any data set or variables if necessary.
Need some help?
HINT:
The code should be very similar to the example in this session.
SOLUTION:
Data Firstname2;
Set Firstname;
Len = Length(Name);
Run;
Note: One of the first name has the length of 50. This clearly does not make sense. The LENGTH function is quite useful in identifying errors in the data cleansing process.
Fill out my online form.