在 SAS 数据步骤中设置重复的数据集
假设我有一个如下所示的 SAS 数据集:
id x
1 1234
2 2345
3 3456
我需要一个新的数据集,该数据集被读取(比如说)2 次,并有一个新变量指示这是哪个“复制”:
id x rep
1 1234 1
2 2345 1
3 3456 1
1 1234 2
2 2345 2
3 3456 2
读取数据很重要按照这个确切的顺序——整个初始数据集被读取一次,然后再次读取,等等。
关于在数据步骤中执行此操作的有效方法有什么想法吗? (实际上我的数据集很大,我需要多次读取它,并且我想避免排序。)
我尝试了这个,但是新数据集中的观察顺序不是我想要的:
data foo;
set tmp; rep=1; output;
set tmp; rep=2; output;
run;
Suppose I have a SAS dataset that looks like this:
id x
1 1234
2 2345
3 3456
I need a new data set that has this data set read in (say) 2 times, with a new variable indicating which "replication" this is:
id x rep
1 1234 1
2 2345 1
3 3456 1
1 1234 2
2 2345 2
3 3456 2
It is important that the data are read in this exact order -- the entire initial data set is read once, then again, etc.
Any ideas on an efficient way to do this in a data step? (In reality my data set is huge, I need to read it several times, and I want to avoid sorting.)
I tried this, but the order of the observations in the new data set is not what I want:
data foo;
set tmp; rep=1; output;
set tmp; rep=2; output;
run;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想保持数据步骤,那么这将按照您所描述的方式工作。
If you want to keep to data step, then this will work as you described.
就是这样。
That's it.
您可以尝试使用视图和过程附加,如下所示:
You could try it using a view and proc append like this: