第54题,下面是题目和crackman的解析,想问下关于 city 和state的长度是否被截断??
谢谢大神们!
54.Consider the following data step:
data WORK.TEST;
setSASHELP.CLASS(obs=5);
retain City'Beverly Hills';
State='California';
run;
The computed variables City and State have their valuesassigned using two different methods, a RETAIN statement and an Assignmentstatement. Which statement regarding this program is true?
A. The RETAINstatement is fine, but the value of City will be truncated to 8
bytes as the LENGTH statement has been omitted.
B. Both theRETAIN and assignment statement are being used to initialize new
variables and are equally efficient. Method used is amatter of programmer preference.
C. The assignmentstatement is fine, but the value of City will be truncated
to 8 bytes as the LENGTH statement has been omitted.
D. City's value will be assigned one time,State's value 5 times.
Answer: D
其实这里考察的RETAIN到底是在非执行语句还是执行语句。
RETAIN的作用是初始化变量为“特定的默认值”,是非执行语句,在编译过程中,PDV中用“特定的默认值”替代SAS系统默认值。在DATA步中,加 入STATE进入PDV中,STATE=’California’; 是赋值语句,也就是执行语句。每一次从SASHELP.CLASS读取数据之后,都要执行一次赋值语句。