在SAS中如何在任意位置插入一行数据呢?
上代码:
data test_data;
set s;
/*output;*/
if _n_ = 8 then do;
do i=1 to 3;
call missing(of x1-x46);
x1='飞哥';
x2='男';
/*output;*/
end;
end;
这段代码,重点在于没有output,那么每行的观测会在data步执行一遍才会写入。set s先将s中的所有变量写入内存即pdv,s中的变量包含x1和x2。执行到第八行时,x1和x2的值会被覆盖。call missing(of x1-x46)是将x1-x46的变量置为空值。这段程序的运行结果如下。
第八行原来的结果被覆盖,没有展现出do i=1 to 3;循环的效果,do循环是为了连续插入三行。此时我没的重点来了。改成如下代码。
data test_data;
set s;
output;
if _n_ = 8 then do;
do i=1 to 3;
call missing(of x1-x46);
x1='飞哥';
x2='男';
output