02-25-2016 12:33 PM
The following SAS DATA step is submitted:
length jobcode$ 12;
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
D. The length can not be determined as the program fails to execute due to errors.
Ans –A (WHY? Why not 12?)
02-25-2016 12:56 PM - edited 02-25-2016 12:57 PM
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.