最近在the little sas book第六章看到只有一个观测值且没有相同合并变量的数据集合并到原始的有多个观测数据集的程序如下:
data new_data_set;
if _n_=1 then set summary_data_set;
set original_data_set;
假设原始数据original_data_set为:
1 ...
2 ...
2 ...
3 ...
3 ...
合并的数据summary_data_set为:total
则结果new_data_set为:
1 ... total
2 ... total
2 ... total
3 ... total
3 ... total
虽然已经知道运行结果,但没有想明白程序的运行原理,书上的解释说因为set语句是自动保留的,summary_data_set只在第一次循环时读入了一次,有其他变量时自动保留了,类似于retain语句,新手实在没看明白,求各位大神指点,谢谢!!!