假设我有一个如下所示的SAS数据集:
id x
1 1234
2 2345
3 3456
Run Code Online (Sandbox Code Playgroud)
我需要一个新数据集,该数据集读入(比如说)2次,新变量指示这是"复制":
id x rep
1 1234 1
2 2345 1
3 3456 1
1 1234 2
2 2345 2
3 3456 2
Run Code Online (Sandbox Code Playgroud)
以正确的顺序读取数据非常重要 - 整个初始数据集只读一次,然后再读取等.
有关在数据步骤中执行此操作的有效方法的任何想法?(实际上我的数据集很大,我需要多次阅读,我想避免排序.)
我尝试过这个,但是新数据集中观察的顺序并不是我想要的:
data foo;
set tmp; rep=1; output;
set tmp; rep=2; output;
run;
Run Code Online (Sandbox Code Playgroud)
如果您想保持数据步骤,那么这将按照您的描述工作.
data foo;
set tmp (in=INA) tmp (in=INB);
if INA then REP=1;
if INB then REP=2;
run;
Run Code Online (Sandbox Code Playgroud)