In this example, we calculate the standard error of sample mean of day 1 calcium intake from foods and beverages. It is possible to use the SAS procedure surveyfreq to calculate the sample mean and corresponding standard error. (In version 9.2, BRR is available as an option, although it cannot be used in combination with the domain statement.) Therefore, the purpose of this example is not to suggest using BRR for this purpose (although it could be done), but to orient readers to the BRR technique that is used throughout the Advanced Dietary Tutorial, with the illustration of a simple example. For the complex models fit in Modules 19-22, BRR is needed to estimate standard errors.
The BRR weights provided in the Advanced Dietary Tutorial dataset demoadv were created by researchers at the Food Surveys Research Group, Agricultural Research Service, US Department of Agriculture.
All of the examples that use BRR in the Advanced Dietary Tutorial use a common structure – the SAS macro. A SAS macro is a useful technique for rerunning a block of code when the analyst only wants to change a few variables. In the case of BRR, it is the sample weights that change in each iteration of the macro call. There are 17 weights in the file. The weight with the _0 (w0304_0) is used for the point estimate of the mean, and the other weights (w0304_1 to w0304_16) are used for the BRR procedure. The main attraction of BRR is that it produces standard errors suitable for NHANES data without using the specialized survey procedures, as long as the differential weighting can be incorporated into each half-sample estimate. Therefore, in this example we use the proc means procedure.
This example uses the demoadv dataset (download at Sample Code and Datasets). This dataset contains a variable dr1tcalc that has a value of calcium intake from day 1 of the 24-hour recall. It also contains BRR weights (w0304_0 to w0304_16). A new dataset is created (wwts) that has the people with BRR weights (those who completed the 24-hour recall).
Statements | Explanation |
---|---|
%macro BRR184; |
The %macro statement is used to indicate the start of the macro BRR184. The statements between the %macro line and the %mend line will be run by SAS each time the macro is invoked. |
proc means data=demoadv noprint; where sel= 1 ; var dr1tcalc; weight w0304_0; output out=m(drop=_type_ _freq_) mean=m_0; run;
|
The proc means procedure is used to estimate the mean of the calcium intake from the first day of 24-hour recalls (dr1tcalc). The first BRR weight (w0304_0) is used for the point estimate of the mean. The output statement saves the mean calcium value (m_0) in a SAS temporary dataset called m. |
data m; set m; mergeby=1; run;
|
This data step adds a variable “mergeby” to the m dataset that will be used to merge the point estimate of the mean with the BRR runs. |
%do i = 1 %to 16;
|
This statement is used within the SAS macro to create a macro variable &i that will be used to indicate the BRR weight that is used (i.e., w0304_&i), and save the value of the mean from the run using that BRR weight (m_&i). The & symbol indicates to SAS to replace the macro variable &i with its value (i.e., the number 1, 2, …, 16). The statements between the %do and the %end will be executed 16 times, each time incrementing &i by 1. |
proc means data=demoadv noprint; var dr1tcalc; weight w0304_&i; output out=tmp(drop=_type_ _freq_) mean=m_&i; run;
|
The proc means procedure is run to calculate the mean using the BRR weights (w0304_1 to w0304_16). The tmp dataset stores the mean for each BRR run. |
data tmp; set tmp; mergeby=1; run;
|
This data step adds a variable “mergeby” to the tmp dataset that will be used to merge the point estimate of the mean with the BRR runs. |
data m; merge m tmp; by mergeby; run;
|
This data step merges the BRR runs with the estimate of the mean from the first run. |
%end; |
The %end statement indicates the end of the %do processing. |
data brr; set m; array reps (16) m_1 - m_16; reps(i) = reps(i) - m_0; end; brrse=sqrt(uss(of m_1-m_16)/(16 * .49)); run;
|
The array statement is also used for repeated processing of a variable. In this case, we want to take the means from the runs with weights w0304_1 to w0304_16 and subtract off m_0 from each of them in the do loop. Next, the BRR standard error (brrse) is computed by dividing the uncorrected sum of squares (uss function) of these differences by H (16) and (1-F)2 (0.49), and taking the square root of this value. |
title 'Mean Calcium Intake of Adults >=50 years' ; proc print data=m; var m_0 brrse; run;
|
This code prints out the mean and corresponding standard error |
%mend BRR184;
|
The %mend statement indicates the end of the BRR184 macro. |
%BRR184
|
The statement %BRR184 invokes SAS to run the BRR184 macro. |