DATA Step, Macro, Functions and more

Length Statement

Reply
Contributor
Posts: 31

Length Statement

QUESTION 64
The following SAS DATA step is submitted:
data work.accountting;
set work.department;
length jobcode$ 12;
run;
The WORK.DEPARTMENT SAS data set contains a character 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?

A. 5
B. 8
C. 12
D. The length can not be determined as the program fails to execute due to errors.

 

 

Ans –A  (WHY? Why not 12?)

Super Contributor
Posts: 490

Re: Length Statement

[ Edited ]
Posted in reply to Bulleride

Because the variable length is already defined by the set statment as in the original data set.

When it will be 12? if the length statment come before the set statament. So order is very important here.

And if you have practicing SAS programming  you will know that if you run this programe you will get a warning.

 WARNING: Length of character variable jobcode has already been set. 
          Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of a character variable.

And not 8 for two reasons the one mentioned above plus this length is not defined any where in the data step or the original data and it is char not number. where if it is number the max length is 8.

Contributor
Posts: 31

Re: Length Statement

Posted in reply to mohamed_zaki
But won't this length statement overwrite the length that the original data set contained and make it 12?
Super Contributor
Posts: 490

Re: Length Statement

[ Edited ]
Posted in reply to Bulleride

No, not in SAS. Only if it come before the set statment in the order in your data step.

Ask a Question
Discussion stats
  • 3 replies
  • 352 views
  • 2 likes
  • 2 in conversation