Handout13 Stat3900/4950 How to take a Stratified random sample from a dataset. source: UCLA Academic Technology Services, Stat Computing, Statistical Computing Resources http://www.ats.ucla.edu/stat/ http://www.ats.ucla.edu/stat/sas/faq/ http://www.ats.ucla.edu/stat/sas/faq/statified_samples.htm Using the SAS datafile hsb2.sas7bdat ------------------------------------------------------------------------------ * Using Proc SurveySelect; proc sort data = "D:\hsb2"; by female; run; options nolabel; proc means data = "D:\hsb2"; by female; run; * 50% sample by female; proc surveyselect data = "D:\hsb2" out = samp1 method = srs samprate = .5 seed = 9876; strata female; run; proc sort data = samp1; by female; run; proc means data = samp1; by female; run; * Merge the data to see which observations were selected; proc sort data = "D:\hsb2"; by id; run; proc sort data = samp1; by id; run; data merge1; set "D:\hsb2" samp1; by id; run; proc print data = merge1 (obs = 25); run; * Using more than one strata; proc sort data = "D:\hsb2"; by female ses prog; run; proc means data = "D:\hsb2"; by female ses; run; * Similar to above with options added; proc surveyselect data = "D:\hsb2" out = samp2 method = srs samprate = .5 seed = 9876; strata female ses; run; proc sort data = samp2; by female ses og; run; proc means data = samp2; by female ses; run; *Using different sampling rates within each strata; proc surveyselect data = "D:\hsb2" out = samp3 method = srs samprate = (.2 .8 .4 .1 .5) seed = 9876; strata female ses; run; proc sort data = samp3; by female ses; run; proc means data = samp3; by female ses; run; * Specifying the number of observations to be sampled in each strata; proc surveyselect data = "D:\hsb2" out = samp4 method = srs n = (15 20 10 30 25) seed = 9876; strata female ses; run; proc sort data = samp4; by female ses; run; proc means data = samp4; by female ses; run; ------------------------------------------------------------------------------