*Call in PAT ACCLEROMETER DATA. Working data set is called Accl_public	*
*This program provides sample code to use when analyzing survey data	*
*There are 679 observations and 91 variables in the dataset	*

The stratification (nesting) variable is strata_pat
The survey weight variable is WT_PATW2ACCEL

For more information, please contact:
NYC Department of Health & Mental Hygiene
Bureau of Epidemiology Services
EpiDatarequest@health.nyc.gov
*********************************************************************;

/* enter path location where where dataset is stored*/

libname pat 'x';

/* format statements and instructions below */
proc format;
value monthf
1="January"
2="February"
3="March"
4="April"
5="May"
6="June"
7="July"
8="August"
9="September"
10="October"
11="November"
12="December";

value yesno_accl
1='Yes'
0='No';

value paga08_3f
1="Inactive"
2="Insufficiently Active"
3="Met Activity Guidelines" ;

value paga08_4f
1="Inactive"
2="Insufficiently Active"
3="Sufficiently Active"
4="Highly Active";

format
month monthf.
PAGA08_3 paga08_3f.
PAGA08_4 paga08_4f.

Valid_Day1 Valid_Day2 Valid_Day3 Valid_Day4 Valid_Day5 Valid_Day6 Valid_Day7 yesno_accl. ;

;

/* place dataset in working directory */
data accl_public;
set pat.accl_public;
run;

/********Instructions for analyzing PAT data*****************
PAT accelerometer data needs to be analyzed using a special procedure in SAS --
proc surveymeans - or using SUDAAN or another software package that
can handle complex survey designs.

If you are only interested in point estimates (i.e. you do not
need standard errors/confidence intervals) using the weight
option in regular SAS procedures, will give the correct point estimates. However,
in order to get confidence intervals you must use proc surveymeans or
another software program capable of accounting for the complex survey design.
************************************************************************************/

**Sample code: Standard errors will not be correct with regular SAS procs, but point
estimates will be fine. Remember to use the weight statement;
proc means data = accl_public;
var Sed_Day1 ;
class valid_day1;
weight WT_PATW2ACCEL;
run;

**Sample code for proc surveymeans - standard errors are correct.
Same point estimates as code above;
proc surveymeans data = accl_public nobs mean clm sum std clsum ;
strata strata_pat; *survey design information;
weight WT_PATW2ACCEL; *weight statement;
var moderate_avg; *variables you are interested in analyzing;
/* class variablename; duplicate variable from var statement if it is categorical; */
domain PAGA08_3; *variable to see estimates stratified by;
run;

/*NOW RUN PROC DESCRIPT*/
proc descript data= accl_public filetype=sas design=strwr NOTSORTED;
nest strata_pat; *survey strata variables*;
weight WT_PATW2ACCEL; *survey weight variable*;
var moderate_avg; *variables you are interested in analyzing; ;
tables PAGA08_3 ; * PAGA08_3 will give you daily average by meeting guidelines*;
class PAGA08_3 ;
setenv decwidth=1; /*Produce output with results rounded to 1 decimal place*/
print/style=nchs; *will print the results*;
output/filename=output12 filetype=sas tablecell=default replace; *produces an output dataset of results*;
title1 'Meeting Activity Guidelines, by Average Number of Moderate Daily Minutes ';
run;

/*Compute the relative standard error of the estimates:
Estimates with RSE >=0.30 or sample sizes <50 are considered unstable:
https://www1.nyc.gov/assets/doh/downloads/pdf/episrv/bes-data-reliability.pdf */
data rsecheck;
set output12;
RSE=SEMEAN/MEAN;
CI_band=UPMEAN-LOWMEAN;
if 0.5 >= RSE >=0.3 then flag='*';
if nsum <50 then flag='*';
if RSE >0.5 and CI_band <=6 then flag='*';
if RSE >0.5 and CI_band >6 then flag='^';
run;

/* run code below to see if any obs were flagged for reliability */

proc print data = rsecheck noobs;
var flag rse nsum CI_band LOWMEAN UPMEAN;
where flag in ('*','^', '**');
run;

/*For more details on age-adjustment, see:
Klein RJ, Schoenborn CA. Age adjustment using the 2000 projected U.S. population. Healthy
People Statistical Notes, no. 20. Hyattsville,Maryland: National Center for Health Statistics.
January 2001. http://www.cdc.gov/nchs/data/statnt/statnt20.pdf */