- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have data from 100 participants on heart rate taken every second they exercised for up to 3 hours, their age, sex, and other demographic information. I need to calculate the amount of time participants spent in different heart rate zones during exercise (60% of max, 80% of max, etc...). The data is in excel but currently each participant has their own excel sheet since the HR data has at times up to 10,000 rows or more. I am attaching a sample excel sheets with data. The first sheet is demographic data for these 4 made up participants. The other sheets are each participants individual heart rate data that is taken every second for the duration of their workout. The activity codes are different types of workouts they were doing. Essentially what I need is the percent of their max heart rate (given in the first master sheet), that they were in for each of their activities and the duration they spent in that max heart rate. So I would need the amount of time each person spent in 50-75% of their max heart rate and the amount of time each person spent in 70-85% of their max heart rate for each activity. If this is confusing please let me know and I can try to clarify. Thank you in advance for any guidance you can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What's the question or portion you need help with?
You've posted your entire project as far as I can see which is well beyond what is fair to ask on a community forum.
if you simplify it and ask specific questions you'll get better responses.
First, have you managed to import the data correctly and combine them as need for a workable data base to analyze?
@rfarmenta wrote:
I have data from 100 participants on heart rate taken every second they exercised for up to 3 hours, their age, sex, and other demographic information. I need to calculate the amount of time participants spent in different heart rate zones during exercise (60% of max, 80% of max, etc...). The data is in excel but currently each participant has their own excel sheet since the HR data has at times up to 10,000 rows or more. I am attaching a sample excel sheets with data. The first sheet is demographic data for these 4 made up participants. The other sheets are each participants individual heart rate data that is taken every second for the duration of their workout. The activity codes are different types of workouts they were doing. Essentially what I need is the percent of their max heart rate (given in the first master sheet), that they were in for each of their activities and the duration they spent in that max heart rate. So I would need the amount of time each person spent in 50-75% of their max heart rate and the amount of time each person spent in 70-85% of their max heart rate for each activity. If this is confusing please let me know and I can try to clarify. Thank you in advance for any guidance you can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I should have been more specific. Yes I can read the data into SAS and have it in long form now with participants stacked on top of each other. I also know how to do the simple calculation for percent of max heart rate for each row of the heart rate data.
maxhrper=(hr/max_hr);
I can then create a variable for heart rate zones using the following code:
if 50<=maxhrper<=75 then hrzone=1;
else if 75<maxhrper<=85 then hrzone=2;
else hrzone=3;
What I don't know how to do is how to apply this to all rows of the data since I have less experience with longitudinal data that is in long format like this. I also am not quite sure how to incorporate the timing in to get the amount of time that each person spent in each heart rate zone for each activity.
I am not sure if this is still too broad. I am trying to mess around with the data to see what I can come up with and can send more details as I have them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then it would probably help to see the data structure you currently have rather than work off your raw data for starters.
The calculation doesn't seem complex to me - having not tried anything yet.
It would be merging each person's ranges into their data, and then calculating the duration for each line if it's in the target zone or not.
Duration can be calculated by simple subtraction. And once that's done, you can use PROC MEANS to summarize the entire data set to get what you need.
For situations like this, I often work backwards, what do I want to see, what do I have, then it helps me connect the dots between the two tables. Otherwise I flounder around trying different things.
@rfarmenta wrote:
Sorry, I should have been more specific. Yes I can read the data into SAS and have it in long form now with participants stacked on top of each other. I also know how to do the simple calculation for percent of max heart rate for each row of the heart rate data.
maxhrper=(hr/max_hr);
I can then create a variable for heart rate zones using the following code:
if 50<=maxhrper<=75 then hrzone=1;
else if 75<maxhrper<=85 then hrzone=2;
else hrzone=3;
What I don't know how to do is how to apply this to all rows of the data since I have less experience with longitudinal data that is in long format like this. I also am not quite sure how to incorporate the timing in to get the amount of time that each person spent in each heart rate zone for each activity.
I am not sure if this is still too broad. I am trying to mess around with the data to see what I can come up with and can send more details as I have them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@rfarmenta wrote:
Sorry, I should have been more specific. Yes I can read the data into SAS and have it in long form now with participants stacked on top of each other. I also know how to do the simple calculation for percent of max heart rate for each row of the heart rate data.
maxhrper=(hr/max_hr);
I can then create a variable for heart rate zones using the following code:
if 50<=maxhrper<=75 then hrzone=1;
else if 75<maxhrper<=85 then hrzone=2;
else hrzone=3;
What I don't know how to do is how to apply this to all rows of the data since I have less experience with longitudinal data that is in long format like this. I also am not quite sure how to incorporate the timing in to get the amount of time that each person spent in each heart rate zone for each activity.
I am not sure if this is still too broad. I am trying to mess around with the data to see what I can come up with and can send more details as I have them.
I admit that I did not look at all of the data but it appears that each measurement occurs at one-second intervals. If that is the design and actual data then a count of each gives you close to a number of seconds (the end points at transition between activities may be a bit questionable) but this would be a start:
Proc freq data=have; tables id*activity*hrzone/output out=need; run;
If you need the count for each section of activity then add a flag to indicate which sequence of activity is involved
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I have the data stacked, and I have the heart zones calculated but I am running into 2 issues. The first is that my time is saved as hh:mm:ss, and I am not sure how to convert that to just seconds in SAS. The second is that I am not sure how to calculate time spent in each heart rate zone for each activity. I am attaching an excel sheet with what the data looks like. The time variable is incorrect because when exporting to excel it is chopping off the seconds right now.
Any advice on how to fix the time issue and calculate time spent in each HR zone for each activity would be great. Thank you for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@rfarmenta wrote:
Ok, I have the data stacked, and I have the heart zones calculated but I am running into 2 issues. The first is that my time is saved as hh:mm:ss, and I am not sure how to convert that to just seconds in SAS. The second is that I am not sure how to calculate time spent in each heart rate zone for each activity. I am attaching an excel sheet with what the data looks like. The time variable is incorrect because when exporting to excel it is chopping off the seconds right now.
Any advice on how to fix the time issue and calculate time spent in each HR zone for each activity would be great. Thank you for your help!
Time is stored in seconds. To convert to seconds, remove the format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Reeza! I now have time in seconds. And since I have one row for each second, I can calculate the time spent in each activity by counting the number of rows I have for each activity. I am doing that using this code:
proc sql;
select count(*) as N_obs
from mod_data
where activity=1 and hrzone=1;
quit;
However, this only gives me output for one zone and 1 activity at a time. I know there has to be a more efficient way to do this for all hrzones and activities. Is there a more efficient way to count the rows for each activity and have that output to a new variable?
Someone suggested using the below code and this gives me the numbers I need in separate tables for each participant. It also outputs several variables, including a Count variable with the data I need I believe, however, I am not sure how to organize that output in a way that is useful for me.
Proc freq data=mod_data;
tables study_id*activity*hrzone/out=need;
run;
Thank you again for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc sql;
create table want as
select activity, hrzone, count(*) as N_obs
from mod_data
group by activity, hrzone;
quit;
proc print data=want;
run;
Or proc means.
PROC MEANS & FREQ are very powerful and worth learning. Guaranteed to be used every day I'm programming in SAS.