/* This sas program will produce the estimates in Example 2.4 of Sampling: Design and Analysis by Sharon L. Lohr, using Version 7 of SAS */ /* Author: S. Lohr, 3/99. Copyright (c) Sharon L. Lohr, 1999. */ options ls=78 ps=35; data agsrs; infile '~atsll/public/stp535/bookdata/agsrs.dat' delimiter= ',' firstobs = 2; input county $ state $ acres92 acres87 acres82 farms92 farms87 farms82 largef92 largef87 largef82 smallf92 smallf87 smallf82; if acres92 < 200000 then lt200k = 1; else lt200k = 0; /* counties with fewer than 200000 acres in farms */ if acres92 = -99 then acres92 = . ; /* check for missing values */ if acres92 = -99 then lt200k = . ; /* Can use proc univariate to calculate summary statistics */ proc univariate data = agsrs plot; var acres92 lt200k; /* proc surveymeans calculates summary statistics, and adjusts for fpc */ title 'Estimating population mean'; proc surveymeans data=agsrs total = 3078; /* Give population size as option */ var acres92 lt200k; /* Note that proc surveymeans gives the 95% confidence interval for the mean as [260706, 335088]. Proc surveymeans uses the t percentile with 299 degrees of freedom here, which is 1.96793. In the book, I used the normal approximation with 1.96. */ /* Can also use proc surveymeans with the sampling weights--- this gives same results */ data agsrs1; set agsrs; wt = 3078/300; /* sampling weight is same for each observation */ title 'Estimating population mean using weights'; proc surveymeans data=agsrs1 total=3078; var acres92 lt200k; weight wt; /* To estimate population total, use 'sum' in options */ title 'Estimating population total using weights'; proc surveymeans data=agsrs1 total=3078 sum; var acres92 lt200k; weight wt; /* The 'class' statement treats a variable as a categorical variable */ title 'Estimating population total using weights'; proc surveymeans data=agsrs1 total=3078 sum; class lt200k; var acres92 lt200k; weight wt;