小宝爱波1314 发表于 2013-12-16 09:26
你好,可以解释一下你的思路么?授之以渔呀,嘿嘿
/* 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