Lucy
Lucy

Reputation: 177

what is the length of this variable?

This is the code:

data work.accounting;
   set work.department;
   length jobcode $ 12;
run;

The work.department sas data set contains a variable named JOBCODE with a length of 5. Which one of the following is the length of the variable JOBCODE in the output data set? The right answer is 5. But I think it should be 12, right? Could anyone explain to me the reason of it? Many thanks for your time and attention.

Upvotes: 0

Views: 262

Answers (2)

Tom
Tom

Reputation: 51621

SAS will define the type and length of a variable as soon as it can. Since JOBCODE exists in the dataset being referenced by the SET statement it will be defined to match how it is defined in the dataset. By the time the compiler sees the LENGTH statement the variable's type and length are already defined. SAS will print a warning message in the log that the length of the variable has already been set.

Upvotes: 1

Vishant
Vishant

Reputation: 266

To change the length,we must use the LENGTH statement as the very first statement in the DATA STEP ,but the position will be changed at the same time. In your code the LENGTH statement has no effect on the length of JOBCODE variable because of this

Upvotes: 0

Related Questions