BookmarkSubscribeRSS Feed
DeJanae07
Calcite | Level 5

Data Truncated

***************************************************************************************

Hello SAS Communities, 

 

I am in the process of creating and restructuring a data set and I am running into trouble with the SSN variable length as well as the formatting length of the numeric variables being automatically set to BEST12. When I initially create the data set the length of the SSN number is $11, however when I move on to restructuring the data set, the length changes to $9. I am unsure why this is happening. Any feedback is appreciated. 

 

Any information on how to get my SSN length to stay at $11 after restructuring the data and how to get rid of the BEST12. format would be great. 

 

Thank you, 

De'Janae' 

2 REPLIES 2
DeJanae07
Calcite | Level 5

Please ignore the "Data Truncated" portion at the beginning. 

 

ballardw
Super User

Since you actually have at least 5 data sets involved the most likely culprit is one or more of the contributing data sets on the SET statement have different properties. Does your log show any message like:

WARNING: Multiple lengths were specified for the variable SSN (or any other variable) by
input data set(s). This can cause truncation of data. ?

 

If so, likely one of the sets that appears earlier in the list has a length of 9.

For brief example:

 

1    data one;
2       x = 'Some characters';
3    run;
4
5    data two;
6       x = 'Is a somewhat longer string';
7    run;

8
9    data combined;
10      set one two;
11   run;

WARNING: Multiple lengths were specified for the variable x by
         input data set(s). This can cause truncation of data.
NOTE: There were 1 observations read from the data set WORK.ONE.
NOTE: There were 1 observations read from the data set WORK.TWO.
NOTE: The data set WORK.COMBINED has 2 observations and 1
      variables.

The most common actual cause is relying on Proc Import, often coupled with a spreadsheet source file. Proc Import will set properties for variables after "examining" a very small number of rows of data. If one file is imported and the longest value in the first few rows is 9, that is what you get, another may have 11.

Worse, with spreadsheets since there isn't any contents restriction you can have mixed character and numeric values in a column so values that should be numeric become character. If the spreadsheet were to have multiple rows of header information then 2nd and subsequent header information is treated as data and complicates things.

If you type "excel import length" into the search bar on the Programming page in this forum you will get around 470 results. Most of them involve issues like yours.

 

 

Personally if the concern only involves SSN I would leave it as numeric and just apply the SAS supplied SSN format to the values.

 

data example;
  input x;
  format x ssn.;
datalines;
123
123456789
;

proc print data=example;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 502 views
  • 0 likes
  • 2 in conversation