Data Set [5-14]

Data Truncation

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

Example

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

Each of the names above is longer than 8 characters.

The default length of a character variable is 8. Any variable that contains more than 8 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

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


Exercise

Create a data set that contains the following variables:

Name the data set as PROFILE.

Need some help?

Get Hint

Get Solution