You may wish to check my work, but I believe you can do it manually as so. The "problem" with surveyselect for your purposes, I believe, is that 1) it uses the natural representation for any strata, whereas you wish to impose weighting/representation (e.g. 50% male/female, x% for groups... you say 10%, but if you're seeking to make them equally represented, as in, with the same rule, as sex, it is actually the number of age groups you are interested in that defines the proportion, as in 10% would be for 10 groups, like 50% is for two sexes), and 2) you also wish to draw only one case per house.
data house;
input id house $ sex $ age;
cards;
1 House1 M 23
2 House1 F 55
3 House2 M 22
4 House2 M 27
5 House3 F 15
6 House3 M 36
7 House3 F 50
8 House3 F 33
9 House3 M 22
10 House3 M 25
11 House3 M 21
12 House4 F 15
13 House4 M 38
14 House5 M 38
15 House5 F 38
16 House6 F 37
;run;
proc sql; create table house2
as select
id,
count(id) as idct,
house,
sex,
count(unique sex) as sexgroupct,
age,
(case when age >= 15 and age < 25 then '15 to 24'
when age >= 25 and age < 35 then '25 to 34'
when age >= 35 then '>=35' end) as agegroup,
count(unique calculated agegroup) as agegroupct
from house
;
quit;
data house3; set house2;
weightgroup = catx('-', sex, agegroup);
run;
proc sql; create table house4
as select
*,
count(weightgroup) as weightgroupct,
(calculated weightgroupct / idct) as weightgroupA,
(1 / sexgroupct) as sexgroupweight,
(1 / agegroupct) as agegroupweight,
(calculated sexgroupweight * calculated agegroupweight) as weightgroupT,
(calculated weightgroupT / calculated weightgroupA) as weight
from house3
group by weightgroup;
quit;
data house5; set house4;
call streaminit(123);
random = rand('Uniform');
randombyweight = (random * weight);
run;
proc sql; create table house6
as select
*
from house5
group by house
having randombyweight = max(randombyweight);
quit;
... View more