Introduction to SAS [10-19]

h

Hey there! Looks like you have not set up the training properly 🙂

This training web page is designed to be open side-by-side with your SAS program.

Please see the instruction on how to set up the training.

Data Truncation

Data Truncation often happens when you create a character variable that is longer than eight characters.

Example

Data Test;
    Input Name $ Gender $;
    Datalines;
    Christopher Male
    Elizabeth Female
    MacDonald Male
    ;
Run;

Each of the names above is longer than eight characters.

The default length of a character variable is eight. Any variable that contains more than eight characters will get cut off.

(Try it!)

The data truncation problem can be easily solved by adding a Length statement.

Example

Data Test;
    Length Name $12;
    Input Name $ Gender $;
    Datalines;
    Christopher Male
    Elizabeth Female
    MacDonald Male
    ;
Run;

The Length statement changes the length of the NAME variable from 8 to 12. 

As a result, the complete name is now captured in the data set.

Note:

Length Name $12;

A dollar sign ($) is added before the number 12. This is needed when adjusting the length of a character variable.


? Sign up for a free SASCrunch account now and keep track of your learning progress!

Exercise

Create a data set that contains the following variables:

Name the data set as PROFILE.

Need some help?

Get Hint

Get Solution