Hi everyone, is it possible to use proc surveyselect to randomly reorder my rows of data within a group variable. For example, in the code below I would like to randomly reorder the rows of data within each site
data have;
input site $ sub $ x1 x2 x3;
datalines;
A A1 1 1 1
A A2 2 2 2
A A3 3 3 3
B B1 4 4 4
C C1 5 5 5
C C2 6 6 6
D D1 7 7 7
;
and i would like get a output data set that looks like this for example.
A A3 3 3 3
A A1 1 1 1
A A2 2 2 2
B B1 4 4 4
C C2 6 6 6
C C1 5 5 5
D D1 7 7 7
I tried using this code but it did not randomly order the rows.
proc surveyselect data=have out=want samprate=1;
strata site;
id _ALL_;
run;
Any help would be appreciated.
P.S. I was able to accomplish this using ranuni and then sorting but I would be prefer to use surveyselect in order to create many replicates and run a simulation.
data have; set have; r=ranuni(0); run;
proc sort data=have out=want; by site r; run;
I'll leave hints on how to use surveyselect to people who know what they're talking about. I'm the last one to ask!
But if you do have to go down the sorting route with ranuni, you can do it in a single pass:
proc sql;
create table want as
select *
from have
order by site, ranuni(0);
quit;
You will get:
Thank you Laurie. I didn't know you could order rows based on variables that are not in the select clause.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.