![]() Chapter Contents |
![]() Previous |
![]() Next |
Statements with the Same Function in Multiple Procedures |
Tip: | You can use a WEIGHT statement and a FREQ statement in the same step of any procedure that supports both statements. |
WEIGHT variable; |
Required Arguments |
Weight value ... | The procedure ... |
0 | counts the observation in the total number of observations |
less than 0 | converts the weight value to zero and counts the observation in the total number of observations |
missing | excludes the observation from the analysis |
Prior to Version 7 of the SAS System, no base procedure excluded the observations with missing weights from the analysis. Most SAS/STAT procedures, such as PROC GLM, have always excluded not only missing weights but also negative and zero weights from the analysis. You can achieve this same behavior in a base procedure that support the WEIGHT statement by using EXCLNPWGT in the PROC statement.
The procedure substitutes the value of the WEIGHT variable for
, which appears in
Keywords and Formulas .
Procedures That Support the WEIGHT Statement |
Note: In
PROC FREQ, the value of the variable in the
WEIGHT statement represents the frequency of occurrence for each observation.
See WEIGHT Statement for more information.
Calculating Weighted Statistics |
By using a WEIGHT statement to compute moments, you assume that the ith observation has a variance that is equal to
. When you specify VARDEF=DF (the default), the computed
variance is a weighted least squares estimate of
. Similarly, the computed standard deviation is an estimate
of
. Note that the computed variance is not an estimate of the variance
of the ith observation, because this variance involves the observation's
weight which varies from observation to observation.
If the values of your variable are counts that represent the number
of occurrences of each observation, use this variable in the FREQ statement
rather than in the WEIGHT statement. In this case, because the values are
counts, they should be integers. (The FREQ statement truncates any noninteger
values.) The variance that is computed with a FREQ variable is an estimate
of the common variance,
, of the observations.
Note: If your data come from a stratified sample where the weights
represent the strata weights, neither the WEIGHT statement
nor the FREQ statement provides appropriate stratified estimates of the mean,
variance, or variance of the mean. To perform the appropriate analysis, consider
using PROC SURVEYMEANS which is a SAS/STAT procedure that is documented in
the SAS/STAT User's Guide.
Example |
The SAS data set SIZE contains the estimate (ObjectSize) at each distance (Distance), and the precision (Precision) for each estimate. Notice that the largest deviation (an overestimate by 8 inches) came at the largest distance (25 feet). As a measure of precision, 1/Distance gives more weight to estimates that were made closer to the object and less weight to estimates that were made at greater distances.
The following statements create the data set SIZE:
options nodate pageno=1 linesize=64 pagesize=60; data size; input Distance ObjectSize @@; Precision=1/distance; datalines; 5 12 5 8 5 12 5 10 10 17 10 13 10 10 10 12 15 10 15 14 15 19 15 13 20 17 20 14 20 9 20 19 25 12 25 10 25 20 25 15 ;The following PROC MEANS step computes the average estimate of the object size while ignoring the weights. Without a WEIGHT variable, PROC MEANS uses the default weight of 1 for every observation. Thus, the estimates of object size at all distances are given equal weight. The average estimate of the object size is overestimated by 1.3 inches.
proc means data=size maxdec=3 n mean var stddev; var objectsize; title1 'Unweighted Analysis of the SIZE Data Set'; run;
proc means data=size maxdec=3 n mean var stddev; weight precision; var objectsize; output out=wtstats var=Est_SigmaSq std=Est_Sigma; title1 'Weighted Analysis Using Default VARDEF=DF'; run; proc means data=size maxdec=3 n mean var std vardef=weight; weight precision; var objectsize; title1 'Weighted Analysis Using VARDEF=WEIGHT'; run;In the first PROC MEANS step, the variance is an estimate of
data wtsize(drop=_freq_ _type_); set size; if _n_=1 then set wtstats; Est_VarObs=est_sigmasq/precision; Est_StdObs=est_sigma/sqrt(precision); proc print data=wtsize noobs; title 'Weighted Statistics'; by distance; format est_varobs est_stdobs est_sigmasq est_sigma precision 6.3; run;
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.