Vandenbroucke, David A
2009-09-04 12:34:48 UTC
I do a lot of work with survey data that must be weighted in order to produce population-level estimates. I can't seem to work out how to get weighted frequencies when using Proc Report. The WEIGHT statement will give weighted sums, means, etc., but the N statistic is always unweighted. Now, unweighted counts are also useful to have, but often I need weighted ones as well, sometimes in the same table. It's not unusual for me to want to cross-tabulate the unweighted count, the weighted frequency, and the mean in the same report.
My work-around has been to use a data step to define a variable as Unit = 1, a constant. Then I can use a SUM statistic to get the weighted frequency. There has to be a better way to do this, without having to go through that extra step.
As an example, here is a Report step using housing data.
ZAdeq = a categorical variable measuring housing quality
ZSMHC = a continuous variable containing the monthly housing cost
SMSA = metropolitan area identifier
Weight = the weighting variable
PROC REPORT DATA=something NOWD;
COLUMN SMSA ZAdeq, (N Unit ZSMHC);
DEFINE SMSA/Group "Metro Area";
DEFINE ZAdeq /Across "Housing Quality";
DEFINE N / "Sample Cases";
DEFINE Unit /SUM "Housing Units";
DEFINE ZSMHC /MEAN "Mean Cost";
WEIGHT Weight;
RUN;
Dav Vandenbroucke
Senior Economist
U.S. Dept. HUD
***@hud.gov
202-402-5890
I disclaim any disclaimers.
My work-around has been to use a data step to define a variable as Unit = 1, a constant. Then I can use a SUM statistic to get the weighted frequency. There has to be a better way to do this, without having to go through that extra step.
As an example, here is a Report step using housing data.
ZAdeq = a categorical variable measuring housing quality
ZSMHC = a continuous variable containing the monthly housing cost
SMSA = metropolitan area identifier
Weight = the weighting variable
PROC REPORT DATA=something NOWD;
COLUMN SMSA ZAdeq, (N Unit ZSMHC);
DEFINE SMSA/Group "Metro Area";
DEFINE ZAdeq /Across "Housing Quality";
DEFINE N / "Sample Cases";
DEFINE Unit /SUM "Housing Units";
DEFINE ZSMHC /MEAN "Mean Cost";
WEIGHT Weight;
RUN;
Dav Vandenbroucke
Senior Economist
U.S. Dept. HUD
***@hud.gov
202-402-5890
I disclaim any disclaimers.