Hello,
I have a data set that is composed of participants and sedentary time. I want to create a new varible that is the average sedentary time for each participant. Meaning that I only want one sedtime for each participant.
I need a new variable because it want to then regress the average sedentary time with other predictors variables.
I am running SAS on SAS studio and I am a beginnier. Any help would be welcome. Thanks
example data.
participant Sedtime
1 4
1 3
1 2
2 1
2 5
2 3
3 4
3 5
3 4
do you mean -
proc sql;
create table want as
select participant, mean(sedtime) as avg
from have
group by participant;
quit;
proc summary data=have nway;
class participant;
var sedtime;
output out=want(drop=_:) mean=/autoname;
run;
Thank you for the information. In this procedure, what is the new variable that was created?
Please test the demo that we share so you will have a clear understanding:
data have;
input participant Sedtime;
datalines;
1 4
1 3
1 2
2 1
2 5
2 3
3 4
3 5
3 4
;
proc summary data=have nway;
class participant;
var sedtime;
output out=want(drop=_:) mean=/autoname;
run;
Results:
participant | Sedtime_Mean |
1 | 3 |
2 | 3 |
3 | 4.333333333 |
Your MERGE doesn’t have a BY statement. I would expect to see one if you’re doing group summaries. Are you sure you’re getting what you expect?
@ebonfil89 wrote:
Hello, I have added the "by" statement. I think that the data was already sorted by ID, so it did give me the same answers. Thank you for your feedback. Very much appreciated it.
If that was the case it means you have a single ID for each record which means there's no point to doing a PROC MEANS. I would be very seriously double checking your results. Something isn't aligning between what you're stating and your code.
You can use PROC MEANS as illustrated here:
https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas
Or you can add it in to your overall data set as illustrated here:
https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas
And there are video tutorials here if you prefer that:
http://video.sas.com/#category/videos/sas-analytics-u/0
Specifically:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.