DATA Step, Macro, Functions and more

WARNING: Multiple lengths were specified for the variable ...

Reply
Frequent Contributor
Posts: 75

WARNING: Multiple lengths were specified for the variable ...

Gday,

I want to remove all error/warning messages from my code.

I have a pretty simple piece of code, where the STATE have been defined with different lengths.

1490
1491 DATA WPolSummary0;
1492 format state $5.;
1493 SET
1494 rateBusPack
1495 rateISR
1496 rateBW
1497 rateCAR
1498 ;
1499 RUN;

WARNING: Multiple lengths were specified for the variable state by input data set(s). This may
cause truncation of data.

NOTE: There were 95507 observations read from the data set WORK.RATEBUSPACK.
NOTE: There were 1822 observations read from the data set WORK.RATEISR.
NOTE: There were 70663 observations read from the data set WORK.RATEBW.
NOTE: There were 19263 observations read from the data set WORK.RATECAR.
NOTE: The data set WORK.WPOLSUMMARY0 has 187255 observations and 32 variables.
NOTE: DATA statement used (Total process time):
real time 2.98 seconds
cpu time 0.96 seconds

^^

The offending dataset is WORK.RATEBW, the length is $255 whereas the rest have been defined as $5.

In this dataset, how can I define the length to a smaller number than the largest value, eg $5?

I have observed that if I specify a larger number, eg $500, there are no errors, but I know that the STATE values are never longer than five character.

I don't want to create a new variable and re-allocate the values.

I don't want to use system options eg VARLENCHK=.


Thanks.


edit:
I should say that I'm using SAS 9.2 on Windows

Message was edited by: John T Message was edited by: John T
Super Contributor
Super Contributor
Posts: 3,174

Re: WARNING: Multiple lengths were specified for the variable ...

Suggest you use a RENAME=(=) as a SET "data set" option, and then perform an INPUT function in an assignment statement to get the desired result without the WARNING message.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

length difference rename dataset option site:sas.com
Frequent Contributor
Posts: 75

Re: WARNING: Multiple lengths were specified for the variable ...

Hi Scott,

Thanks for your response, but I don't want that solution.

For the time being, this was my solution:

DATA WPolSummary0;
length state $500. state2 $5.;
SET
rateBusPack
rateISR
rateBW
rateCAR
;

state2 = state;
drop state;
rename state2 = state;
RUN;

^^

Which is essentially, what you suggested.

I don't want to perform renaming of variables, if I can get away with it. Any other ideas?
Super User
Posts: 3,115

Re: WARNING: Multiple lengths were specified for the variable ...

I suspect you are using SAS 9.2 and the VARLENCHK system option is set to WARN. If you want to turn off the warning try:

options VARLENCHK = NOWARN;

This is the default SAS 9.1.3 behaviour.
Super Contributor
Super Contributor
Posts: 3,174

Re: WARNING: Multiple lengths were specified for the variable ...

So, do also consider that by setting the VARLENCHK option to NOWARN, you may be masking another possible problem symptom condition that could go unnoticed. I suggest you reconsider the RENAME= approach without limiting yourself with the NOWARN approach. I have similar recommendations for using SAS OPTIONS DKRICOND / DKROCOND with NOWARN as well.

Scott Barry
SBBWorks, Inc.
New Contributor
Posts: 3

Re: WARNING: Multiple lengths were specified for the variable ...

Maybe Scott refered to something like this, which I usually use for adapting dates to Excel format and somehow prefer as more beautiful:

 

DATA WPolSummary0 (DROP=state_old);
length state $5.;
SET
rateBusPack
rateISR
rateBW (RENAME=(state=state_old))
rateCAR
;

state=state_old;
RUN;

Cheers!
(Is this actually used as a "goodbye"? Best wishes or best regards maybe sounds  like "too much" here ^^)

Frequent Contributor
Posts: 75

Re: WARNING: Multiple lengths were specified for the variable ...

Hi,

Thanks, I honestly did not expect a solution, I trawled google for an hour looking for one.

As Scott mentioned, I don't want to use that system option, as it will hide the real errors.

Really, I just wanted to make beautiful code. That and remove error/warning messages in the code, so when other people in the team run it, they aren't falsely alerted to issues.

The use of the rename statement, whilst it works, in this case, I would no regard as beautiful. For the time being it is what I'm using.
Super Contributor
Super Contributor
Posts: 3,174

Re: WARNING: Multiple lengths were specified for the variable ...

Okay - whatever steers your mouse-cursor.....beautiful, efficient, well-documented or otherwise operational....

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 632

Re: WARNING: Multiple lengths were specified for the variable ...

Assuming that you have control (don't we all wish for just such a thing?) of the creation of the incoming data sets, beautiful code would require cleaning up, assigning the correct length to STATE, in the data set WORK.RATEBW. Then the whole problem goes away.
SAS Employee
Posts: 19

Re: WARNING: Multiple lengths were specified for the variable ...

If you don't mind that the variable state is stored with length 255 in the WPolSummary, and if you don't need the rate* data sets to be in any particular order in the set statement, you can also just switch around the data set names so that rateBW is first in the set statement.

set rateBW rateBusPack rateISR rateCAR;
Ask a Question
Discussion stats
  • 9 replies
  • 15089 views
  • 0 likes
  • 6 in conversation