老师在讲授数组和Retain时有这样一个例子
Example 7.11: We are given a time series data for the daily air pollution index.
Suppose the data are stored in a SAS data file, POLLUTE. It has two variables,
namely DATE (a numeric variable) and INDEX. Furthermore, it is assumed that the
records are in ascending order of DATE, and no two records in POLLUTE have the
same DATE value. The time series data start on 1 JAN 2005. Write a program to
create a temporary data set, called MISSD, storing the date when the pollution index
is missing.
利用数组:
DATA MISSD;
KEEP J;
ARRAY K(1) (0); * K1 STORES THE PRECEDING DATE;
SET POLLUTE;
If K1=0 THEN K1=MDY(1,1,2005)-1;
If DATE ^= K1+1 THEN DO J=K1+1 TO DATE-1; OUTPUT; END;
K1=DATE;
RUN;
利用RETAIN:
DATA MISSD;
KEEP J;
RETAIN K 0; * K1 STORES THE PRECEDING DATE;
SET POLLUTE;
If K=0 THEN K=MDY(1,1,2005)-1;
If DATE ^= K+1 THEN DO J=K+1 TO DATE-1; OUTPUT; END;
K=DATE;
RUN;
请问,为什么在使用数组时不需要加RETAIN呢?
对于DATA STEP我可不可以这么理解,data step其实是暗含循环的,有多少记录就迭代多少次,而每次每个变量的值都是重新获取的,如果没有retain修饰的话。
那么按照这个理解,在每次循环时,数组变量的值也都应该是重新获取的啊?