Don't forget to create account on our site to get access to more material made only for free registered user.  
SAS A00-211 Certification SAS A00-212 Certification Questions and Answers SAS A00 240 Certification Material SAS A00-250 Exam Material Certification SAS Packaged Solutions

Question 15 : The following SAS program is submitted:data work.accounting;
set work.dept1 work.dept2;
jobcode = `FA1';
length jobcode $ 8;
run;A character variable named JOBCODE is contained in both the WORK.DEPT1 and WORK.DEPT2 SAS data sets.
The variable JOBCODE has a length of 5 in the WORK.DEPT1 data set and a length of 7 in the WORK.DEPT2 data set.
What is the length of the variable JOBCODE in the output data set?

1. 3
2. 5
3. 7
4. 8
Correct Answer : 2
Exp : The "set statement" takes the length of the common variable, as the length of that variable in the first dataset of set statement. The length of a variable always define automatically in the first statement and remain unchanged during the whole program until and unless we redefine it.So when DEPT1 is set the lenght will set to 5 and remain unchanged during the data step, reason is length of the first placed dataset's variable's length will be taken, not the second placed.If set work.dept2 work.dept1;then the answer is 7. the length of a char var is fixed in work dataset1 and it takes same length while copying new value into it
for example data
 try;a='asdfg';
a='abcdefg';
put @5 a;
run;in log window we will find a value as abcde only 5 chars  the char var takes first defined val length while numeric var by default it will take 12.
Setting the Length of Character Variables
This example illustrates why you may want to specify a length for a character variable, rather than let the first assigned value determine the length. Because New York City has two airports, both the abbreviations for John F. Kennedy International Airport and La Guardia Airport can be assigned to the Airport variable as in the DATA step.
Note:   When you create character variables, SAS determines the length of the variable from its first occurrence in the DATA step. Therefore, you must allow for the longest possible value in the first statement that mentions the variable. If you do not assign the longest value the first time the variable is assigned, then data can be truncated.2

You have no rights to post comments