1 The SAS System 08:55 Tuesday, March 13, 2007 NOTE: Copyright (c) 1999-2001 by SAS Institute Inc., Cary, NC, USA. NOTE: SAS (r) Proprietary Software Release 8.2 (TS2M0) Licensed to NATIONAL INSTITUTES OF HEALTH, Site 0040679003. NOTE: This session is executing on the WIN_PRO platform. NOTE: SAS initialization used: real time 0.12 seconds cpu time 0.12 seconds NOTE: AUTOEXEC processing beginning; file is C:\Program Files\SAS Institute\SAS\V9.1\autoexec.sas. NOTE: Libref GDEVICE0 was successfully assigned as follows: Engine: V8 Physical Name: C:\Documents and Settings\DoddK\My Documents\SASGRAPH NOTE: AUTOEXEC processing completed. 1 *------------------------------------------------------------------------------------ 1 ! --------------------*; 2 *create.pam_perday.sas 2 ! *; 3 * 3 ! *; 4 *Purpose: summarize valid PAM data into one record per person per day. The summary 4 ! record contains *; 5 * derived variables on duration of non-wear periods as well as activity bouts 5 ! with moderate, *; 6 * vigorous, and moderate or vigorous intensity. 6 ! *; 7 * 7 ! *; 8 *Before running the code below: 8 ! *; 9 *1. Modify the libname statement to refer to the folder where you want to store the 9 ! input and output *; 10 * datasets. 10 ! *; 11 *2. Save PAM_formats.txt (included with these programs) and list the full path in the 11 ! *; 12 * %include statement below. You will need to include these formats in any program 12 ! that *; 13 * uses the output dataset. 13 ! *; 14 *3. Run create.pam_perminute.sas to create the input dataset pam_perminute. 14 ! *; 15 *4. Create a SAS dataset named demo_c in that folder from the Demographic data from 15 ! *; 16 * http://www.cdc.gov/nchs/about/major/nhanes/nhanes2003-2004/demo03_04.htm. 16 ! *; 2 The SAS System 08:55 Tuesday, March 13, 2007 17 *------------------------------------------------------------------------------------ 17 ! --------------------*; 18 libname myfolder "&home/EATS_NHANES/sasdata"; NOTE: Libref MYFOLDER was successfully assigned as follows: Engine: V8 Physical Name: C:\Documents and Settings\DoddK\My Documents\EATS_NHANES\sasdata 19 libname demo xport "&home/EATS_NHANES/sasdata/demo_c.xpt"; NOTE: Libref DEMO was successfully assigned as follows: Engine: XPORT Physical Name: C:\Documents and Settings\DoddK\My Documents\EATS_NHANES\sasdata\demo_c.xpt 19 ! * Added by kwd; 20 %include "&home/EATS_NHANES/sasprog/AccelerometryPA/PAM_formats.sas"; NOTE: Format YESNO has been output. NOTE: Format WKDAY has been output. NOTE: Format GENDER has been output. NOTE: Format AGEGRP has been output. NOTE: PROCEDURE FORMAT used: real time 0.03 seconds cpu time 0.00 seconds 55 56 *---------------------------------------------------------------------*; 57 *Read in the edited PAM dataset created by create.pam_perminute.sas. *; 58 *Get age variable from the demog file--age is needed later to create *; 59 *age-dependent physical activity variables. Only keep people with *; 60 *PAXCAL=1 (the monitor was in calibration). This excludes 346 people. *; 61 *---------------------------------------------------------------------*; 62 data monitors; 63 * merge myfolder.pam_perminute(in=in_pam) myfolder.demo_c(in=in_demog keep=seqn 63 ! ridageyr); 64 merge myfolder.pam_perminute(in=in_pam) demo.demo_c(in=in_demog keep=seqn ridageyr) 64 ! ;* Added by kwd; 65 by seqn; 66 if in_pam; 67 if not in_demog then put 'ERROR! not in demog' seqn=; 68 if paxcal=1; 69 run; NOTE: There were 72250027 observations read from the data set MYFOLDER.PAM_PERMINUTE. NOTE: There were 10122 observations read from the data set DEMO.DEMO_C. NOTE: The data set WORK.MONITORS has 68779007 observations and 10 variables. NOTE: DATA statement used: real time 2:20.44 cpu time 1:20.85 70 71 *------------------------------------------------------------------------------------ 71 ! --------------------*; 72 *Macro %nw defines the duration of non-wear periods as well as wear periods within a 72 ! day based on user *; 3 The SAS System 08:55 Tuesday, March 13, 2007 73 *defined minimum length of non-wear period. 73 ! *; 74 * 74 ! *; 75 *A non-wear period starts at a minute with the intensity count of zero. Minutes with 75 ! intensity count=0 or*; 76 *up to 2 consecutive minutes with intensity counts between 1 and 100 are considered 76 ! to be valid non-wear *; 77 *minutes. A non-wear period is established when the specified length of consecutive 77 ! non-wear minutes is *; 78 *reached. The non-wear period stops when any of the following conditions is met: 78 ! *; 79 * - one minute with intensity count >100 79 ! *; 80 * - one minute with a missing intensity count 80 ! *; 81 * - 3 consecutive minutes with intensity counts between 1 and 100 81 ! *; 82 * - the last minute of the day 82 ! *; 83 * 83 ! *; 84 *Macro call %nw(nwperiod=); 84 ! *; 85 *nwperiod: minimum length for the non-wear period, must be >1 minute. 85 ! *; 86 *------------------------------------------------------------------------------------ 86 ! --------------------*; 87 %macro nw(nwperiod=); 88 data nw_all; 89 set monitors; 90 by seqn day paxn; 91 92 if first.day then nw_num=0; /*non-wear period number*/ 93 94 if first.day or reset or stopped then do; 95 strt_nw=0; /*starting minute for the non-wear period*/ 96 end_nw=0; /*ending minute for the non-wear period*/ 97 start=0; /*indicator for starting to count the non-wear period*/ 98 dur_nw=0; /*duration for the non-wear period*/ 99 reset=0; /*indicator for resetting and starting over*/ 100 stopped=0; /*indicator for stopping the non-wear period*/ 101 cnt_non_zero=0; /*counter for the number of minutes with intensity between 1 and 101 ! 100*/ 102 end; 103 retain nw_num strt_nw end_nw stopped reset start cnt_non_zero dur_nw; 104 105 /*The non-wear period starts with a zero count*/ 106 if paxinten=0 and start=0 then do; 107 strt_nw=paxn; /*assign the starting minute of non-wear*/ 108 start=1; 109 end; 110 4 The SAS System 08:55 Tuesday, March 13, 2007 111 /*accumulate the number of the non-wear minutes*/ 112 if start and paxinten=0 then 113 end_nw=paxn; /*keep track of the ending minute for the non-wear period*/ 114 115 /*keep track of the number of minutes with intensity between 1-100*/ 116 if 0100 intensity*/ 126 if (cnt_non_zero=3 or paxinten=. or paxinten>100 ) then do; 127 if dur_nw<&nwperiod then reset=1; /*reset if less than &nwperiod minutes of 127 ! non-wear*/ 128 else stopped=1; 129 end; 130 131 /*last minute of the day*/ 132 if last.day and dur_nw>=&nwperiod then stopped=1; 133 134 /*output one record for each non-wear period*/ 135 if stopped=1 then do; 136 nw_num=nw_num+1; 137 keep seqn day nw_num strt_nw end_nw dur_nw; 138 output; 139 end; 140 run; 141 142 *---------------------------------------------------------------------*; 143 *summarize the non-wear periods to one record per day *; 144 *---------------------------------------------------------------------*; 145 proc summary data=nw_all ; 146 by seqn day; 147 var dur_nw ; 148 output out=sum_nw 149 sum=tot_dur_nw 150 run; 151 152 *-------------------------------------------------------------------------*; 153 *summarize the total number of valid minutes for everyone in the analysis.*; 154 *-------------------------------------------------------------------------*; 155 proc summary data=monitors; 156 by seqn day ridageyr paxday; 157 var paxinten; 158 output out=sum_all 159 n=tot_min; 160 run; 5 The SAS System 08:55 Tuesday, March 13, 2007 161 162 *---------------------------------------------------------------------*; 163 *define hours of wear *; 164 *---------------------------------------------------------------------*; 165 /*create a dataset with one record per minute, for the non-wear periods only*/ 166 data nw_minutes(keep=seqn day paxn); 167 set nw_all; 168 by seqn day nw_num; 169 do i=strt_nw to end_nw by 1; 170 paxn=i; 171 output; 172 end; 173 run; 174 175 /*create a dataset from the monitor data, restricted to the wear periods*/ 176 data wear_minute(keep=seqn day paxn paxinten); 177 merge monitors(in=in_all) nw_minutes(in=in_nw); 178 by seqn day paxn; 179 if in_all and not in_nw; 180 run; 181 182 /*summarize the wear minutes */ 183 proc summary data=wear_minute; 184 by seqn day; 185 var paxinten; 186 output out=sum_wear 187 sum=tot_cnt_wr 188 n=tot_min_wr; 189 run; 190 191 *---------------------------------------------------------------------*; 192 *final data for one record per day for everyone in the analysis. *; 193 *---------------------------------------------------------------------*; 194 data nw&nwperiod; 195 merge sum_all(in=in_all) sum_nw(in=in_nw) sum_wear; 196 by seqn day; 197 if in_all; 198 199 if tot_dur_nw=. then tot_dur_nw=0; 200 if tot_min_wr=. then tot_min_wr=0; 201 if tot_cnt_wr=. then tot_cnt_wr=0; 202 203 wear_hr=tot_min_wr/60; 204 tot_dur_nw=tot_dur_nw/60; 205 label 206 tot_dur_nw='Total duration(hr) of non-wear periods in a day' 207 wear_hr='Total number of wear hours for the day' 208 tot_min='Total number of valid minutes within a day' 209 tot_cnt_wr='Total intensity counts from all wear minutes in a day' 210 tot_min_wr='Total number of wear minutes in a day' 211 ; 212 keep seqn paxday day ridageyr tot_min tot_min_wr wear_hr tot_cnt_wr tot_dur_nw; 213 run; 6 The SAS System 08:55 Tuesday, March 13, 2007 214 215 %mend nw; 216 217 %nw(nwperiod=60); /* this is where the duration criterion for a non-wear period is 217 ! set */ NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.NW_ALL has 111119 observations and 6 variables. NOTE: DATA statement used: real time 3:09.37 cpu time 1:05.31 NOTE: There were 111119 observations read from the data set WORK.NW_ALL. NOTE: The data set WORK.SUM_NW has 47606 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.21 seconds cpu time 0.17 seconds NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.SUM_ALL has 47771 observations and 7 variables. NOTE: PROCEDURE SUMMARY used: real time 2:59.62 cpu time 23.92 seconds NOTE: There were 111119 observations read from the data set WORK.NW_ALL. NOTE: The data set WORK.NW_MINUTES has 37790925 observations and 3 variables. NOTE: DATA statement used: real time 36.42 seconds cpu time 7.42 seconds NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: There were 37790925 observations read from the data set WORK.NW_MINUTES. NOTE: The data set WORK.WEAR_MINUTE has 30988082 observations and 4 variables. NOTE: DATA statement used: real time 5:58.60 cpu time 1:52.01 NOTE: There were 30988082 observations read from the data set WORK.WEAR_MINUTE. NOTE: The data set WORK.SUM_WEAR has 45236 observations and 6 variables. NOTE: PROCEDURE SUMMARY used: real time 34.27 seconds cpu time 10.28 seconds 7 The SAS System 08:55 Tuesday, March 13, 2007 NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 47606 observations read from the data set WORK.SUM_NW. NOTE: There were 45236 observations read from the data set WORK.SUM_WEAR. NOTE: The data set WORK.NW60 has 47771 observations and 9 variables. NOTE: DATA statement used: real time 0.91 seconds cpu time 0.12 seconds 218 219 *------------------------------------------------------------------------------------ 219 ! -----------*; 220 *Activity bouts defined by specified number of minutes with intensity count >= the 220 ! threshold *; 221 * 221 ! *; 222 *An activity bout starts at a minute with an intensity count greater than or equal to 222 ! the *; 223 *threshold. Minutes with intensity count greater than or equal to the threshold are 223 ! considered *; 224 *to be valid minutes for the activity bout. A bout is established when the specified 224 ! length of *; 225 *consecutive valid minutes are reached. The activity bout stops when any of the 225 ! following *; 226 *conditions is met: 226 ! *; 227 * - one minute with intensity < threshold 227 ! *; 228 * - one minute with a missing intensity count 228 ! *; 229 * - the last minute of the day 229 ! *; 230 *------------------------------------------------------------------------------------ 230 ! -----------*; 231 232 *--------------------------------------------------------------*; 233 *Flag the intensity counts that are above the threshold. *; 234 *Use different activity bout criteria for different age groups.*; 235 *NOTE: to change the cutoff points for moderate or vigorous *; 236 * intensity, please modify the statements below for *; 237 * variables modthresh(moderate threshold) and *; 238 * vigthresh(vigorous threshold). *; 239 *--------------------------------------------------------------*; 240 data monitors; 241 set monitors; 242 /*moderate threshold*/ 243 if ridageyr=6 then modthresh=1400; 244 else if ridageyr=7 then modthresh=1515; 245 else if ridageyr=8 then modthresh=1638; 246 else if ridageyr=9 then modthresh=1770; 247 else if ridageyr=10 then modthresh=1910; 8 The SAS System 08:55 Tuesday, March 13, 2007 248 else if ridageyr=11 then modthresh=2059; 249 else if ridageyr=12 then modthresh=2220; 250 else if ridageyr=13 then modthresh=2393; 251 else if ridageyr=14 then modthresh=2580; 252 else if ridageyr=15 then modthresh=2781; 253 else if ridageyr=16 then modthresh=3000; 254 else if ridageyr=17 then modthresh=3239; 255 else if ridageyr>=18 then modthresh=2020; 256 257 /*vigorous threshold*/ 258 if ridageyr=6 then vigthresh=3758; 259 else if ridageyr=7 then vigthresh=3947; 260 else if ridageyr=8 then vigthresh=4147; 261 else if ridageyr=9 then vigthresh=4360; 262 else if ridageyr=10 then vigthresh=4588; 263 else if ridageyr=11 then vigthresh=4832; 264 else if ridageyr=12 then vigthresh=5094; 265 else if ridageyr=13 then vigthresh=5375; 266 else if ridageyr=14 then vigthresh=5679; 267 else if ridageyr=15 then vigthresh=6007; 268 else if ridageyr=16 then vigthresh=6363; 269 else if ridageyr=17 then vigthresh=6751; 270 else if ridageyr>=18 then vigthresh=5999; 271 272 /*moderate or vigorous activity*/ 273 if paxinten>=modthresh then _mv=1; 274 else if paxinten ne . then _mv=0; 275 276 /*vigorous activity*/ 277 if paxinten>=vigthresh then _v=1; 278 else if paxinten ne . then _v=0; 279 280 /*moderate activity*/ 281 if modthresh<=paxinten= the threshold is encountered*/ 315 if &bout_flg=1 and start=0 then do; 316 strt_mv=paxn; /*assign the starting minute of the bout*/ 317 start=1; 318 end; 319 320 /*accumulate minutes with intensity counts >= the threshold*/ 321 if start=1 and &bout_flg=1 then do; 322 mv_cnt=mv_cnt+1; 323 end_mv=paxn; /*keep track of the ending minute for the bout*/ 324 end; 325 326 /*stop when encounter a minute with intensity < threshold or missing*/ 327 if &bout_flg in (0,.) then do; 328 if mv_cnt<&boutperiod then reset=1; /*reset if less than the bout length*/ 329 else stopped=1; 330 end; 331 332 /*last minute of the day*/ 333 if last.day and mv_cnt>=&boutperiod then stopped=1; 334 335 /*output one record for each activity bout*/ 336 if stopped=1 then do; 337 dur_mv=end_mv-strt_mv+1; 10 The SAS System 08:55 Tuesday, March 13, 2007 338 mv_num=mv_num+1; 339 output; 340 label 341 strt_mv='Starting minute for the activity bout' 342 end_mv='Ending minute for the activity bout' 343 dur_mv='Duration(minutes) of activity bout' 344 mv_num='Number of activity bout' 345 ; 346 end; 347 keep seqn day mv_num strt_mv end_mv dur_mv ; 348 run; 349 350 proc sort data=out&bout_flg&boutperiod; 351 by seqn day mv_num; 352 run; 353 354 *-----------------------------------------------*; 355 *calculate total duration of activity bouts for *; 356 *each day. *; 357 *-----------------------------------------------*; 358 proc summary data=out&bout_flg&boutperiod; 359 by seqn day; 360 var dur_mv; 361 output out=sum_mv 362 sum=tot_dur_mv; 363 run; 364 365 *-----------------------------------------------*; 366 *output one record per day for each person in *; 367 *the analysis. *; 368 *-----------------------------------------------*; 369 data out&bout_flg&boutperiod._sum; 370 merge sum_all(in=in_all) sum_mv; 371 by seqn day; 372 if in_all; 373 if tot_dur_mv=. then tot_dur_mv=0; 374 label 375 %if &bout_flg=_mv %then %do; 376 tot_dur_mv="Total duration(minutes) of moderate or vigorous activity bouts 376 ! (minimum &boutperiod minute bouts) in a day" 377 %end; 378 %if &bout_flg=_m %then %do; 379 tot_dur_mv="Total duration(minutes) of moderate activity bouts (minimum 379 ! &boutperiod minute bouts) in a day" 380 %end; 381 %if &bout_flg=_v %then %do; 382 tot_dur_mv="Total duration(minutes) of vigorous activity bouts (minimum 382 ! &boutperiod minute bouts) in a day" 383 %end; 384 ; 385 keep seqn day tot_dur_mv; 386 rename 387 tot_dur_mv=tot_dur&bout_flg&boutperiod; 11 The SAS System 08:55 Tuesday, March 13, 2007 388 run; 389 %mend bouts; 390 391 *-----------------------------------------------*; 392 *create activity bouts with moderate, vigorous, *; 393 *and moderate or vigorous intensity. *; 394 *-----------------------------------------------*; 395 %macro boutsgrp(boutperiod); 396 %bouts(bout_flg=_mv,boutperiod=&boutperiod); 397 %bouts(bout_flg=_v,boutperiod=&boutperiod); 398 %bouts(bout_flg=_m,boutperiod=&boutperiod); 399 %mend boutsgrp; 400 401 *-----------------------------------------------*; 402 *set bout length here (now set to 1 min) *; 403 *-----------------------------------------------*; 404 %boutsgrp(1); /*value here is bout length criterion*/ NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.OUT_MV1 has 591804 observations and 6 variables. NOTE: DATA statement used: real time 7:38.37 cpu time 1:12.06 NOTE: There were 591804 observations read from the data set WORK.OUT_MV1. NOTE: The data set WORK.OUT_MV1 has 591804 observations and 6 variables. NOTE: PROCEDURE SORT used: real time 13.40 seconds cpu time 1.17 seconds NOTE: There were 591804 observations read from the data set WORK.OUT_MV1. NOTE: The data set WORK.SUM_MV has 39553 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.32 seconds cpu time 0.31 seconds NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 39553 observations read from the data set WORK.SUM_MV. NOTE: The data set WORK.OUT_MV1_SUM has 47771 observations and 3 variables. NOTE: DATA statement used: real time 0.93 seconds cpu time 0.13 seconds NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.OUT_V1 has 66484 observations and 6 variables. 12 The SAS System 08:55 Tuesday, March 13, 2007 NOTE: DATA statement used: real time 6:25.66 cpu time 1:12.10 NOTE: There were 66484 observations read from the data set WORK.OUT_V1. NOTE: The data set WORK.OUT_V1 has 66484 observations and 6 variables. NOTE: PROCEDURE SORT used: real time 0.12 seconds cpu time 0.10 seconds NOTE: There were 66484 observations read from the data set WORK.OUT_V1. NOTE: The data set WORK.SUM_MV has 12220 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.06 seconds cpu time 0.03 seconds NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 12220 observations read from the data set WORK.SUM_MV. NOTE: The data set WORK.OUT_V1_SUM has 47771 observations and 3 variables. NOTE: DATA statement used: real time 0.07 seconds cpu time 0.07 seconds NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.OUT_M1 has 607275 observations and 6 variables. NOTE: DATA statement used: real time 6:33.96 cpu time 1:12.32 NOTE: There were 607275 observations read from the data set WORK.OUT_M1. NOTE: The data set WORK.OUT_M1 has 607275 observations and 6 variables. NOTE: PROCEDURE SORT used: real time 8.11 seconds cpu time 1.20 seconds NOTE: There were 607275 observations read from the data set WORK.OUT_M1. NOTE: The data set WORK.SUM_MV has 39462 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.32 seconds cpu time 0.32 seconds 13 The SAS System 08:55 Tuesday, March 13, 2007 NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 39462 observations read from the data set WORK.SUM_MV. NOTE: The data set WORK.OUT_M1_SUM has 47771 observations and 3 variables. NOTE: DATA statement used: real time 0.09 seconds cpu time 0.09 seconds 405 406 *------------------------------------------------------------------------------------ 406 ! ---------*; 407 *Macro %bouts_8of10 defines activity bouts for 8 out of 10 minutes with intensity 407 ! count >= the*; 408 *threshold. 408 ! *; 409 * 409 ! *; 410 *An activity bout starts with a count that is greater than or equal to the threshold. 410 ! *; 411 *A bout is established when 8 minutes out of a 10 minute window have intensity counts 411 ! greater *; 412 *than or equal to the threshold. The bout stops when any of the following conditions 412 ! is met: *; 413 * - 3 consecutive minutes with intensity < threshold 413 ! *; 414 * - one minute with a missing intensity count 414 ! *; 415 * - last minute of the day 415 ! *; 416 * 416 ! *; 417 *Macro call %bouts_8of10(bout_flg=); 417 ! *; 418 *bout_flg: variable name for activity bout intensity, _m(moderate), _v(vigorous), 418 ! *; 419 * _mv(moderate or vigorous) 419 ! *; 420 *------------------------------------------------------------------------------------ 420 ! ---------*; 421 %macro bouts_8of10(bout_flg=); 422 data out&bout_flg; 423 set monitors; 424 by seqn day paxn; 425 /*set up a 10 minute window*/ 426 array win_paxn(*) win_paxn1-win_paxn10; /*minute*/ 427 array win_int(*) win_int1-win_int10; /*intensity*/ 428 array win_flg(*) win_flg1-win_flg10; /*bout flag*/ 429 430 if first.day then 431 mv_num=0; /*number of activity bouts*/ 432 14 The SAS System 08:55 Tuesday, March 13, 2007 433 if first.day or stopped or reset then do; 434 strt_mv=0; /*starting minute for the bout*/ 435 end_mv=0; /*ending minute for the bout*/ 436 found=0; /*set to 1 if a bout has been established*/ 437 reset=0; /*reset the counts and start over*/ 438 stopped=0; /*indicator for stopping the bout*/ 439 start=0; /*start set to 1 if one above the threshold count is 439 ! encountered*/ 440 mv_cnt=0; /*number of minutes with counts >= the threshold*/ 441 sum10=.; /*the total intensity counts from the 10 minute window*/ 442 cnt_below=0; /*counter for number of minutes with intensity below the 442 ! threshold*/ 443 do i=1 to 10; /*initialize the 10 minute window*/ 444 win_paxn(i)=0; 445 win_int(i)=0; 446 win_flg(i)=0; 447 end; 448 end; 449 retain mv_num reset strt_mv end_mv start mv_cnt found stopped sum10 cnt_below; 450 retain win_paxn1-win_paxn10; 451 retain win_int1-win_int10; 452 retain win_flg1-win_flg10; 453 454 /*if the intensity count is >= the threshold, start the bout*/ 455 if &bout_flg=1 and start=0 then 456 start=1; 457 458 /*accumulate the counts*/ 459 if start=1 then mv_cnt=mv_cnt+1; 460 461 /*set up a moving window of 10 minutes*/ 462 if 1<=mv_cnt<=10 and not found then do; 463 win_paxn(mv_cnt)=paxn; 464 win_int(mv_cnt)=paxinten; 465 win_flg(mv_cnt)=&bout_flg; 466 if paxinten = . then reset=1; /*if encounter a missing count before reaching 466 ! the 10 minute count, reset and start again*/ 467 end; 468 469 /*when reach 10 minutes, count the total number of intensity counts that are >= 469 ! threshold*/ 470 if mv_cnt=10 and not reset then sum10=sum(of win_flg1-win_flg10); 471 472 /*if 8 out of 10 minutes with intensity counts >= the threshold, a bout is 472 ! established*/ 473 if sum10>=8 then found=1; 474 475 /*if less than 8 minutes with intensity counts>= the threshold, continue to 475 ! search*/ 476 /*move the 10-minute window down, one minute at a time*/ 477 else if 010 then do; 478 if paxinten=. then reset=1; /*if the 10th minute has a missing count, reset 478 ! and start again*/ 15 The SAS System 08:55 Tuesday, March 13, 2007 479 else do; 480 do i=1 to 9; 481 win_paxn(i)=win_paxn(i+1); 482 win_int(i)=win_int(i+1); 483 win_flg(i)=win_flg(i+1); 484 end; 485 /*read in minute 10*/ 486 win_paxn(10)=paxn; 487 win_int(10)=paxinten; 488 win_flg(10)=&bout_flg; 489 sum10=sum(of win_flg1-win_flg10); 490 end; 491 end; 492 if sum10 in (0) then reset=1; /*skip the windows with no valid 492 ! minutes*/ 493 494 /*after the bout is established*/ 495 if found then do; 496 /*assign the starting minute for the activity bout*/ 497 if strt_mv= 0 then do; 498 do i=1 to 10; 499 if win_flg(i)=1 then do; /*find the first minute with intensity 499 ! count>=the threshold*/ 500 strt_mv=win_paxn(i); 501 i=11; 502 end; 503 end; 504 end; 505 /*assign the ending minute for the activity bout*/ 506 if end_mv=0 then do; 507 /*the last 2 minutes in the 10 minute window are below the threshold*/ 508 if win_flg(9)=0 and win_flg(10)=0 then do; 509 end_mv= win_paxn(8); 510 cnt_below=2; 511 end; 512 /*the last minute in the 10 minute window is below the threshold*/ 513 else if win_flg(10)=0 then do; 514 end_mv=win_paxn(9); 515 cnt_below=1; 516 end; 517 else 518 end_mv=win_paxn(10); 519 end; 520 if paxn>win_paxn(10) then do; 521 if &bout_flg=1 then do; 522 cnt_below=0; 523 end_mv=paxn; 524 end; 525 if &bout_flg=0 then 526 cnt_below=cnt_below+1; /*keep track of the number of minutes with 526 ! intensity counts below the threshold*/ 527 end; 528 /*bout terminates if 3 consecutive minutes below the threshold are encountered, 16 The SAS System 08:55 Tuesday, March 13, 2007 528 ! or a missing count, or the last minute of the day*/ 529 if cnt_below=3 or last.day or &bout_flg=. then stopped=1; 530 end; 531 /*output one record for each activity bout*/ 532 if stopped=1 then do; 533 dur_mv=end_mv-strt_mv+1; 534 mv_num=mv_num+1; 535 keep seqn day mv_num strt_mv end_mv dur_mv; 536 output; 537 end; 538 run; 539 proc sort data=out&bout_flg; 540 by seqn day mv_num; 541 run; 542 543 *-----------------------------------------------*; 544 *calculate total duration of activity bouts for *; 545 *each day. *; 546 *-----------------------------------------------*; 547 proc summary data=out&bout_flg; 548 by seqn day; 549 var dur_mv; 550 output out=sum_mv 551 sum=tot_dur_mv; 552 run; 553 554 *-----------------------------------------------*; 555 *output one record per day for each person in *; 556 *the analysis. *; 557 *-----------------------------------------------*; 558 data out&bout_flg._sum; 559 merge sum_all(in=in_all) sum_mv; 560 by seqn day; 561 if in_all; 562 if tot_dur_mv=. then tot_dur_mv=0; 563 564 label 565 %if &bout_flg=_mv %then %do; 566 tot_dur_mv="Total duration(min) of moderate or vigorous activity bouts (8 out of 566 ! 10 minutes) in a day" 567 %end; 568 %if &bout_flg=_m %then %do; 569 tot_dur_mv="Total duration(min) of moderate activity bouts (8 out of 10 minutes) 569 ! in a day" 570 %end; 571 %if &bout_flg=_v %then %do; 572 tot_dur_mv="Total duration(min) of vigorous activity bouts (8 out of 10 minutes) 572 ! in a day" 573 %end; 574 ; 575 576 keep seqn day tot_dur_mv; 577 17 The SAS System 08:55 Tuesday, March 13, 2007 578 rename 579 tot_dur_mv=tot_dur&bout_flg; 580 run; 581 %mend bouts_8of10; 582 583 %bouts_8of10(bout_flg=_mv); NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.OUT_MV has 24166 observations and 6 variables. NOTE: DATA statement used: real time 6:42.77 cpu time 1:24.34 NOTE: There were 24166 observations read from the data set WORK.OUT_MV. NOTE: The data set WORK.OUT_MV has 24166 observations and 6 variables. NOTE: PROCEDURE SORT used: real time 0.04 seconds cpu time 0.03 seconds NOTE: There were 24166 observations read from the data set WORK.OUT_MV. NOTE: The data set WORK.SUM_MV has 11306 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.04 seconds cpu time 0.04 seconds NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 11306 observations read from the data set WORK.SUM_MV. NOTE: The data set WORK.OUT_MV_SUM has 47771 observations and 3 variables. NOTE: DATA statement used: real time 0.07 seconds cpu time 0.07 seconds 584 %bouts_8of10(bout_flg=_v); NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.OUT_V has 1869 observations and 6 variables. NOTE: DATA statement used: real time 6:31.24 cpu time 1:09.53 NOTE: There were 1869 observations read from the data set WORK.OUT_V. NOTE: The data set WORK.OUT_V has 1869 observations and 6 variables. NOTE: PROCEDURE SORT used: real time 0.01 seconds 18 The SAS System 08:55 Tuesday, March 13, 2007 cpu time 0.01 seconds NOTE: There were 1869 observations read from the data set WORK.OUT_V. NOTE: The data set WORK.SUM_MV has 1382 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.01 seconds cpu time 0.00 seconds NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 1382 observations read from the data set WORK.SUM_MV. NOTE: The data set WORK.OUT_V_SUM has 47771 observations and 3 variables. NOTE: DATA statement used: real time 0.07 seconds cpu time 0.06 seconds 585 %bouts_8of10(bout_flg=_m); NOTE: There were 68779007 observations read from the data set WORK.MONITORS. NOTE: The data set WORK.OUT_M has 17144 observations and 6 variables. NOTE: DATA statement used: real time 6:39.30 cpu time 1:25.13 NOTE: There were 17144 observations read from the data set WORK.OUT_M. NOTE: The data set WORK.OUT_M has 17144 observations and 6 variables. NOTE: PROCEDURE SORT used: real time 0.01 seconds cpu time 0.01 seconds NOTE: There were 17144 observations read from the data set WORK.OUT_M. NOTE: The data set WORK.SUM_MV has 9478 observations and 5 variables. NOTE: PROCEDURE SUMMARY used: real time 0.03 seconds cpu time 0.03 seconds NOTE: There were 47771 observations read from the data set WORK.SUM_ALL. NOTE: There were 9478 observations read from the data set WORK.SUM_MV. NOTE: The data set WORK.OUT_M_SUM has 47771 observations and 3 variables. NOTE: DATA statement used: real time 0.12 seconds cpu time 0.09 seconds 19 The SAS System 08:55 Tuesday, March 13, 2007 586 587 *-----------------------------------------------------------*; 588 *summarize to one record per person per day with duration *; 589 *of non-wear and activity bouts *; 590 *-----------------------------------------------------------*; 591 data pam_perday; 592 merge nw60 593 out_mv_sum out_v_sum out_m_sum 594 out_mv1_sum out_v1_sum out_m1_sum ; 595 by seqn day; 596 run; NOTE: There were 47771 observations read from the data set WORK.NW60. NOTE: There were 47771 observations read from the data set WORK.OUT_MV_SUM. NOTE: There were 47771 observations read from the data set WORK.OUT_V_SUM. NOTE: There were 47771 observations read from the data set WORK.OUT_M_SUM. NOTE: There were 47771 observations read from the data set WORK.OUT_MV1_SUM. NOTE: There were 47771 observations read from the data set WORK.OUT_V1_SUM. NOTE: There were 47771 observations read from the data set WORK.OUT_M1_SUM. NOTE: The data set WORK.PAM_PERDAY has 47771 observations and 15 variables. NOTE: DATA statement used: real time 0.45 seconds cpu time 0.31 seconds 597 598 *------------------------------------------------------------------------------------ 598 ! ------*; 599 *Copy the work dataset pam_perday to the folder referenced by the libname statement 599 ! above. *; 600 *------------------------------------------------------------------------------------ 600 ! ------*; 601 data myfolder.pam_perday; 602 set pam_perday; 603 run; NOTE: There were 47771 observations read from the data set WORK.PAM_PERDAY. NOTE: The data set MYFOLDER.PAM_PERDAY has 47771 observations and 15 variables. NOTE: DATA statement used: real time 0.20 seconds cpu time 0.04 seconds 604 605 proc contents data=myfolder.pam_perday; 606 run; NOTE: PROCEDURE CONTENTS used: real time 0.98 seconds cpu time 0.00 seconds NOTE: The PROCEDURE CONTENTS printed pages 1-2. 20 The SAS System 08:55 Tuesday, March 13, 2007 607 608 *------------------------------------------------------------------------------------ 608 ! ------*; 609 *You have now created a dataset that has one record per person per day. It contains 609 ! the *; 610 *variables listed in pam_perday_contents.doc. It is used in create.pam_perperson.sas 610 ! to *; 611 *create a dataset with one record per person, and it may also be used for other 611 ! analyses. *; 612 *------------------------------------------------------------------------------------ 612 ! ------*; 613 NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE: The SAS System used: real time 1:56:11.11 cpu time 18:47.79