楼主: bluehaiku
3823 2

proc sql中的order by 部分求解释 [推广有奖]

  • 10关注
  • 2粉丝

已卖:16份资源

讲师

75%

还不是VIP/贵宾

-

威望
0
论坛币
795 个
通用积分
14.0008
学术水平
5 点
热心指数
5 点
信用等级
5 点
经验
8765 点
帖子
212
精华
0
在线时间
639 小时
注册时间
2015-11-12
最后登录
2025-6-7

楼主
bluehaiku 发表于 2016-9-20 17:31:10 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
/* see the notes in the code below */
/* the idea is to add a variable of random number */
/* then sort the dataset by the random number of the new variable */
/* then output the specified number of observations to a new dataset */
/* this can also be done using a few data steps within a macro */

data allData;        /* sample dataset with 1100 observations as your original dataset */
   do id = 10001 to 11100;                  /* one ID variable */
       x = round(ranuni(12345)*100, 0.01);  /* x and y are two other variable */
       y = round(ranuni(12345)*100, 0.01);
      output;
   end;
run;

%macro samp;
    %let seed=1234;           /* initial seed used for generating random number */
    %do i = 1 %to 10;         /* loop: control the number of datasets to be generated */

      proc sql outobs=100;    /* PROC SQL for creating one sampling dataset */   
         create table sample&i. as  /* outobs= : control the number of observations sampled */
         select *
         from alldata
         order by ranuni(&seed);   /* creating a column of random number  */
      quit;                        /* for ordering the dataset */

      %let seed = %eval(&seed+2);  /* changing the seed for next sampling */
    %end;                          /* end of do-loop */  
%mend samp;
%samp






这段程序可以从1000个观测的数据集中,抽取100个观测的样本,随机抽取10次。程序时,人大论坛的一位大神写的,我copy了下,但对程序不太理解,order by 后面跟着一个随机变量,这个随机变量和数据集alldata没有任何关系,求问这是为啥呢

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:proc sql Order ROC der sql specified original number within 1100

沙发
liujunhzau524 发表于 2016-9-20 19:35:33
就是按照生成的随机数排序,这样就能达到每次随机抽取100条数据的效果

藤椅
bluehaiku 发表于 2016-9-21 08:49:57
liujunhzau524 发表于 2016-9-20 19:35
就是按照生成的随机数排序,这样就能达到每次随机抽取100条数据的效果
好像是数据集的随机排序

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-3 20:50