Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
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.
Picture

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;
Picture

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.
Picture

Write a SAS program to find out the length of each name. 

Create any data set or variables if necessary.
Next

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.

Already a member? Go to member's area.