f*****k 发帖数: 110 | 1 In the book for SAS adv prep is an example on Creating a Random Sample
without Replacement on P459. Who can help me to understand the logic behind
the method. Or any other better methods? Thanks a lot.
The example and codes are posted below:
Example
You can use a DO WHILE loop to avoid replacement as you create your random
sample. In the following example
# Sasuser.Revenue is the original data set.
# sampsize is the number of observations to read into the sample.
# Work.Rsubset is the data set that contains the random sample that you are
creating.
# obsleft is the number of observations in the original data set that have
not yet been considered for selection.
# totobs is the total number of observations in the original data set.
# pickit is the number of the observation to be read into the sample data
set (if the
RANUNI expression is true), and its starting value is 0.
With each iteration of the DO loop, pickit is incremented by 1. If the
RANUNI
expression is true, the observation that is indicated by the value of pickit
is selected
for the sample, and sampsize is decreased by 1. If the RANUNI expression is
not true,
the observation that is indicated by the value of pickit is not added to the
sample. On
each iteration of the loop, obsleft is decreased by 1 regardless of whether
the
observation is selected for the sample. The process ends when the value of
sampsize is
0 and no additional observations are needed.
data work.rsubset(drop=obsleft sampsize);
sampsize=10;
obsleft=totobs;
do while(sampsize>0);
pickit+1;
if ranuni(0)
set sasuser.revenue point=pickit
nobs=totobs;
output;
sampsize=sampsize-1;
end;
obsleft=obsleft-1;
end;
stop;
run; | s*********r 发帖数: 909 | | f*****k 发帖数: 110 | 3 这个PROC好用!谢谢。
SAS adv的方法不是化简为繁么?SAS adv的方法实用吗?
【在 s*********r 的大作中提到】 : proc suveyselect
| n******r 发帖数: 1247 | 4 Ironically the code above is linear time and is much faster than proc
surveyselect implementing the same function on large data sampling.
【在 s*********r 的大作中提到】 : proc suveyselect
| n******r 发帖数: 1247 | 5 this is the fastest sampling without replacement algorithm and it is very
neat too
【在 f*****k 的大作中提到】 : 这个PROC好用!谢谢。 : SAS adv的方法不是化简为繁么?SAS adv的方法实用吗?
|
|