SAS:如何随机提取X年
因此,有一个数据集包含Y年数据,我的问题是如何随机选择X年以上的样本。 例如;有2001年至2005年的观察结果
表明,我想在总计5年的数据中随机两年吗?例如(2001年和2003年; 2001和2002;等) 我该如何在数据步骤中而不是使用PROC调查选择中执行此操作,因为我还没有达到这一点。如果在数据步骤中无法完成如何解决?
data have;
input fyear data;
datalines;
2001 123
2002 123
2001 123
2003 123
2001 123
2003 123
2004 123
2005 123
2001 123
2003 123
;
run;
So, There is a dataset contains Y years data in total, My question is how to select a sample that has X years out of Y years randomly.
For instance; there is 2001 to 2005 years observations
say I want two random years out of a total of 5 years data? For example (2001 and 2003; 2001 and 2002;etc)
How can i do this in a DATA step instead of using PROC SURVEY SELECTION, since I haven't reach that. If it cant be done in DATA step how to solve it?
data have;
input fyear data;
datalines;
2001 123
2002 123
2001 123
2003 123
2001 123
2003 123
2004 123
2005 123
2001 123
2003 123
;
run;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个宏变量,该变量在数据集中拥有所有年份的随机列表。列表中的前两个值将是随机的有效年份。
查看宏变量
& YARS
:我们可以在语句中的
中直接使用它:
更改Proc SQL中
OutObs
的值增加或减少随机年数。Create a macro variable that holds a distinct randomized list of all years in your dataset. The first two values in the list will be random valid years.
Take a look at the macro variable
&years
:We can use this directly in an
in
statement:Change the value of
outobs
in PROC SQL to increase or decrease the number of random years.