chtongueek
chtongueek

Reputation: 123

SAS proc surveyselect don't sort output

I'm using a PROC SURVEYSELECT statement to get random numbers from a set of integers. SAS then returns the sampled integers but in ascending order, and I need them to remain in random order. How would I either randomly mix the output from the SURVEYSELECT statement, or just get the statement not to sort? I can't seem to find any option that lets the statement just output in the order that it randomly selects.

Here's the code:

proc surveyselect data=data noprint
method=srs
n=numOfSamps
seed=123
out=outputSet
run;

As always, thanks in advance!

Upvotes: 0

Views: 685

Answers (3)

Jetzler
Jetzler

Reputation: 797

If you just want to random sort your final stratified sample you can use ranuni() and proc sort.

data data;
    set data;
    rn = ranuni(12345);
run;
proc sort data = data; by rn; run;

Upvotes: 1

Joe
Joe

Reputation: 63434

This is the default of SURVEYSELECT, if you have just a single SRS.

data have;
  call streaminit(7);
  do _order = 1 to 1e6;
    intnum = floor(rand('Uniform')*1e9);
    output;
  end;
run;


proc surveyselect data=have noprint
method=srs
n=10000
seed=123
out=outputSet;
run;

As you can see from the included _ORDER variable, it's not sorted in any way - it still retains the initial ordering (and there's nothing special about that variable).

Now, if you are doing stratified SRS, which is implied by your use of a dataset name in the above code (but you leave the details of that out), it will get sorted, and you need to include the _ORDER variable or something similar, and then re-sort by that variable to return to your original order.

Upvotes: 0

data _null_
data _null_

Reputation: 9109

To generate a random permutation of integers size n of x you can use PROC PLAN. I don't know how that would fit with your SRS but then you don't tell the whole story do you?

proc plan;
   factors x=10 of 100 random / noprint;
   output out=x10;
   run;
   quit;

enter image description here

Upvotes: 0

Related Questions