Help using Base SAS procedures

Do I need to write length statement thrice?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

Do I need to write length statement thrice?

Hi SAS Forum,

In the following code, I have introduced the lengths of variables named Account_number, Short_name and country to get rid of the warning message below (SAS Discussion Forum supported me on this, and now no warnings).

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

data k.unified_dataset;

length Account_number $ 32;

length Short_name $ 23;

length country $ 26;

set any_name_1

      any_name_2 (in=inb  rename=(account_name=short_name Net_Write_off_total_USD=balance));

by bank_number account_number current_date;

if inb then Arrears_Band='writoff ';

run;

Question:

Do I need to write the “length” statement thrice? Can I cut short like this…

length Account_number $ 32 Short_name $ 23 country $ 26;

Your help is greatly appreciated.

Thanks

Mirisage


Accepted Solutions
Solution
‎09-10-2012 04:51 PM
Super User
Posts: 5,099

Re: Do I need to write length statement thrice?

IF you are still getting WARNINGS ...

Regardless of whether you have one LENGTH statement or three, that's not solving your problem.  Evidently $23 is not long enough.  Check your PROC CONTENTS results.  You will find one of these (or both):

In ANY_NAME_1, SHORT_NAME already exists and has a length longer than $23.

In ANY_NAME_2, ACCOUNT_NAME has a length longer than $23.

Changing the number of LENGTH statements will not affect the source of this WARNING.  Supplying an adequate length for SHORT_NAME is necessary.

Good luck.

View solution in original post


All Replies
PROC Star
Posts: 7,366

Re: Do I need to write length statement thrice?

Not meaning to sound rude, but couldn't you just have tested that yourself?

In any case, the answer is that you can put them all on one length statement.

Super User
Posts: 3,115

Re: Do I need to write length statement thrice?

Also without meaning to be rude, this type of question can also be quickly and easily answered by checking the SAS documentation, either in the Help installed with SAS or in the online help. If I have a similar problem I always look there first and if you find the answer it saves time not having to post a question.

Solution
‎09-10-2012 04:51 PM
Super User
Posts: 5,099

Re: Do I need to write length statement thrice?

IF you are still getting WARNINGS ...

Regardless of whether you have one LENGTH statement or three, that's not solving your problem.  Evidently $23 is not long enough.  Check your PROC CONTENTS results.  You will find one of these (or both):

In ANY_NAME_1, SHORT_NAME already exists and has a length longer than $23.

In ANY_NAME_2, ACCOUNT_NAME has a length longer than $23.

Changing the number of LENGTH statements will not affect the source of this WARNING.  Supplying an adequate length for SHORT_NAME is necessary.

Good luck.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 179 views
  • 6 likes
  • 4 in conversation