SAS Base (32)

Consider the following data step:

data WORK.NEW;
set WORK.OLD;
Count+1;
run;

The variable Count is created using a sum statement. Which statement regarding this variable is true?
A. It is assigned a value 0 when the data step begins execution.
B. It is assigned a value of missing when the data step begins execution.
C. It is assigned a value 0 at compile time.
D. It is assigned a value of missing at compile time.

Check Answer
Answer: C

注解:Count + 1为一个Sum Statement,等价于:
RETAIN Count 0;
Count = SUM(Count, 1);

RETAIN的作用是初始化一个变量,并且在每次进入新的DATA step时,保留该变量的值。值得注意的是,RETAIN statement在编译代码时执行,即在执行DATA step(读取数据)之前,所以RETAIN statement只执行一次。SUM function的作用是求合,并且忽略missing value。上面程序第一句的意思为初始化一个叫Count的变量,并且其初始值为0。第二行的作用是将Count的值增加1,与Count = Count + 1类似,但两者有一个重要的区别,SUM function会忽略missing value,而后一种表达式则不会。假设Count的值为missing,Sum(Count, 1)的结果为1,而Count + 1的结果则为missing,missing value加上一个值其结果还是missing。