LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 7 Aug 2008 13:36:24 -0400
Reply-To:   Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject:   Re: Arrays - help
In-Reply-To:   <200808061549.m76Al1NE027296@malibu.cc.uga.edu>
Content-Type:   text/plain; charset=ISO-8859-1

On Wed, Aug 6, 2008 at 11:49 AM, sam <samygeb@gmail.com> wrote:

> Hi all > > I am wrestling with this problem, I am sure some body could help me. I am > posting the question again. I have a 24 hours blood pressure data with > measurments taken every 20 minutes. The data looks some thing like this: I > have more than 1000 subjects. > > ID SystBp Time > 01 140 8:30 (starting time) > 01 135 8:50 > 01 136 9:10 > . . . > . . . > . . . > 01 135 8:30 (ending time- the next day) > > 02 137 9:30 (starting time) > 02 125 9:50 > . . . > . . . > . . . > 02 135 9:30 (ending time- the next day) > > 03 122 14:50 (start time) > 03 130 15:10 > 03 134 15:30 > . . . > . . . > . . . > 03 137 15:50 (ending time- the next day) > > I want to derive variables 24 hour mean systbp, mean systbp every 3 hours > and mean daytime systbp and nighttime bp in such away that the newly > derived dataset is one observation pre subject. > > The desired output > > Id 24hmean systbp3 systbp6 systbp9... systbp24 daytimebp nighttimebp > 01 127.5 130.5 . . . . . > 02 135.8 125.6 . . . . . > 03 140.9 124.7 . . . . . > > I tried to use arrays to solve the problem but I have no luck so far. > > Thank you > sam >

Sam,

Kannan has given good solutions. I have a one step solution using DoW loop.

In the example data I use, time measured in seconds. The next day time will be more than 24:00:00. The night-time will be between 64,600 to 208,000 seconds. Keeping time this way helps in the accumulations of sysBp. The output includes mean BP for 8 periods in h1 to h8 and the day-time and night-time mean are in dn1 and dn2(Check yourself the results).

** Create a dataset; data have; do ID = 1 to 3; start = 30600 + ceil(ranuni(123) * 36000); endtime = start + 85200; do t = start to endtime by 1200; *time = mod(t,86400); time = t; SysBp = 95 + ceil(ranuni(123) * 40); output; end; end; keep id time sysbp; run;

** See how TIME is created;

proc print data = have; format time time8.; run;

data need; do until(last.id); set have; by id;

array hrly[*] h1 - h8; array dn[*] dn1 - dn2; * you could use temporary array instead; array d[0:1] _temporary_; array d_count[0:1] _temporary_;

if first.id then do; stime = time; d[0] = 0; d_count[0] = 0; d[1] = 0; d_count[1] = 0; end;

** sum for daytimes and nighttimes;

k = 64800 le time lt 108000; * k = 1 for night-time and k = 0 for otherwise; d[k] + sysbp; d_count[k] + 1;

if (time - stime) < 10800 then do; * 3-hour gaps; hr_sum = sum(hr_sum, sysbp); hr_count = sum(hr_count , 1); ** last row before id_break; if last.id then do; hrly[period + 1] = hr_sum / hr_count; dn[1] = d[0] / d_count[0]; dn[2] = d[1] / d_count[1]; end; end; else do; stime = time; period = sum(period,1); hrly[period] = hr_sum / hr_count; hr_sum = sysbp; hr_count = 1; end; end; keep id h1 - h8 dn: ; run;

proc print noobs data = need; run;

Output :

ID h1 h2 h3 h4 h5 h6 h7 h8 dn1 dn2 1 110.889 118.889 119.667 113.000 119.667 119.000 114.222 117.667 117.667 115.583 2 107.556 115.778 118.111 123.333 110.889 120.444 113.444 116.889 114.833 116.778 3 115.222 115.333 118.444 114.222 115.556 122.333 115.111 116.333 115.944 117.194

Regards,

Muthia Kachirayan


Back to: Top of message | Previous page | Main SAS-L page