BookmarkSubscribeRSS Feed
DeJanae07
Calcite | Level 5

Data Truncated

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

Hello SAS Communities, 

 

I am in the process of combining three data set vertically and ran into the following warning messages: 

"Multiple lengths were specified for the variable by input data set(s). This can cause truncation of data"

"Length of character variable has already been set" 

 

For all three data sets I have set the lengths of the variables as follows:

 

How can I fix this problem of truncation so that I have a total of 598 observations in my output (combination of data from all three data sets), instead of only 196 observations that are being read in from the first data set before truncation occurs?

 

Thank you, 

De'Janae' 

       

 

3 REPLIES 3
ballardw
Super User

The only variable you need to fix would be the Inits (unless you are getting other messages about the other variables).

 

In the data step where you are attempting to combine these data sets you can set a length for the problem variable(s) that is at least as long as the longest assigned length prior to any Set, Merge or similar statement.

 

Data want;

    length inits $ 10;

    set data1 data2 data3;

run;

 

for example. You may still see a message but the data wouldn't be truncated. Or go back to when all of the sets are created and insure that lengths are the same. If you are getting that message then your claim that all the variables have that length means you either are doing it after attempting to combine the data or was not done in all of the data sets.

Tom
Super User Tom
Super User

You cannot change the length of a character variable once it has been determined.  That is what the second message is telling you.  So you probably tried to do something like this:

data want;
  set have;
  length inits $3 ;
run;

Once SAS sees that INITS is already in HAVE then the LENGTH statement will be ignored and you will get that warning.

You can fix this by changing the order of the LENGTH and SET statements so that the lengths are defined before SAS check how they are defined in the incoming dataset.

 

Also watch out for character variables with display formats attached.  If you set the length of INITS to $3 but the first dataset in your SET statement that has a format attached has something shorter, like $2., attached to it then when you print the values the third character will not be displayed.  You can use a format statement without any format specification to remove the formats attached to varaibles.

format _character_;

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
  • 3 replies
  • 479 views
  • 3 likes
  • 4 in conversation