DATA Step, Macro, Functions and more

Data step Length

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Data step Length

Hi,

I think this is a simple solution, but I can't seem to figure it out.

I have multiple datasets in the exact same data layout that i'd like to concatenate using the data step.

for example:

data merged ;

set table1 table2 table3 table4 ;

run ;

A variable may have different lengths in each of the tables so when I run the code above I get the warning:

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

I tried adding the length statement but still got the warning.

How can I set the length so I do not get the warning?

Thanks for your help.


Accepted Solutions
Solution
‎07-21-2011 02:29 PM
PROC Star
Posts: 7,363

Data step Length

options varlenchk=nowarn;

View solution in original post


All Replies
PROC Star
Posts: 7,363

Data step Length

I can't test this at the moment, but do you still get the error if the place the length statement(s) before the set statement?

Contributor
Posts: 66

Data step Length

yes the warning still shows up if do:

data merged ;

length product $15 ;

set table1 table2 table3 table4 ;

run ;

PROC Star
Posts: 7,363

Data step Length

How about if, in your set statement, you put the file with the longest lengths first (leftmost) on the list?

Respected Advisor
Posts: 3,777

Data step Length

My limited testing shows that if you still have the warning it means that one or more of the varables from the input data sets have a length longer than you have defined.  You could use PROC CONTENTS and PROC SUMMARY to determine the MAX length of each variable and code gen LENGTH/ATTRIB statements to resolve the issue.

Contributor
Posts: 66

Data step Length

Is their a way to force the length for the new dataset?

for example:

table1: Product $15

table2: Product $15

table3: Product $17

table4: Product $15

for some reason i have some dirty records in table3 that makes the product variable $17, In my merged dataset I want to make product $15, and its fine if its truncated.

PROC Star
Posts: 7,363

Data step Length

You are doing that with the length statement or by ensuring that the culprit is not the first file.  Or are you asking how to do it without having to confront the warnings?

Contributor
Posts: 66

Data step Length

yes exactly, is there a way around the warning?

Solution
‎07-21-2011 02:29 PM
PROC Star
Posts: 7,363

Data step Length

options varlenchk=nowarn;

Contributor
Posts: 66

Data step Length

Great thanks for your help.

☑ This topic is SOLVED.

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

Discussion stats
  • 9 replies
  • 255 views
  • 0 likes
  • 3 in conversation