sas - randomly select two observation and calculate the distance -
i have data set have
numerical column x
. want randomly select 2 distinct points , calculate distance between them.
if once, use proc surveyselect
generate data set 2 obs.
proc surveyselect data=have out=want method=srs sampsize=2; run; data out; set have end=eof; dist = abs(dif1(x)); if eof; run;
but how can multiple times, 1000000? each time 2 points selected equal prob, have 1000000 dist records.
how reorder input dataset random order , calculate distance every second observation?
proc sql ; create table random select *, ranuni(0) randorder have order randorder ;quit ; data want ; set random; dist=abs(dif1(x)) ; if _n_/2=int(_n_/2) ; run;
if need specify specific number of samples calculate can add update set random
set random(obs=100000)
example. although note 'sample pairs' 100,000 give want
dataset 50,000 observations
Comments
Post a Comment