I have several datasets with the same structure(two variables:"code" and "group") while different in dataset name(with no rule). Now I have to do simple random sampling in these datasets, the method is selcet one observation from each "group" randomly. I know how to write the basic programme:
data sample;
set original;
where group=‘group_value’;
run;
proc surveyselect data=sample method=srs n=1 seed=821 out=fsample;
run;
I want to process these datasets more efficiently but I know little about sas macro, anyone can give me some advice on using sas macro to do this?
Even better with PROC SURVEYSELECT is the STRATA option.
data have;
do group = 1 to 5;
do x = 1 to 5;
output;
end;
end;
run;
proc surveyselect data=have n=1 out=want;
strata group;
run;
STRATA
will as for a sample of n
items per unique value of the strata
variable. (Also works on percents.) Also requires sorting (because it works more or less like by
).