Hi everyone, I am using SAS 9.4. version and I have to select a sample using a complex stratification process that involves several strata and a weight assigned to each observation. I created a fake data file to give you a better sense of how the data are structured (attached). The data are structured in 5 strata (domain_name) and 4 of the 5 strata have 2 sub-strata (shade). Each strata is also distributed in 9 bands and the final sample size must be done by each stratum, sub-stratum, and band in a specific proportion/number. Finally, each observation has assigned a weight-score which must be taken into account: the highest the weight-score, the higher the probability of being selected. So far, I was able to select a partial sample--the strata that has missing substrata is never selected and I need help figuring out how to select observations from that stratum. Below is the code I used. proc freq data=population noprint; tables domain_name*shade*band/out= framedist; run; data sampsize; do shade=1 to 2; do band= 1 to 9; input nfract @@; output; end; end; datalines; 0 1 6 38 60 70 35 10 2 0 0 1 7 11 12 6 2 0 0 1 8 49 78 91 46 13 2 0 0 1 9 14 16 8 2 0 0 1 8 51 81 94 48 14 2 0 0 1 9 14 17 8 2 0 0 0 4 27 42 49 25 7 1 0 0 5 28 45 52 26 8 1 0 0 1 5 8 9 5 1 0 ; data sampsize; set sampsize; _nsize_ = round(nfract) ; if 0<nfract<1 then _nsize_=1; run; proc print; /*this code outputs the data and sums up the total sample size; I replaced _nsize_ with nfract*/ sum nfract; run; proc sort data=sampsize; by Shade band; run; proc sort data=framedist; by Shade band; run; data sampsize; merge sampsize framedist; by shade band; if _nsize_=. then _nsize_=0; run; proc surveyselect data=test sampsize =sampsize seed= 56789 out=sample2 selectall noprint; strata shade band; run; Thank you so much!
... View more