02-17-2018 04:31 PM
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
02-17-2018 04:38 PM - edited 02-17-2018 04:42 PM
do you mean -
proc sql; create table want as select participant, mean(sedtime) as avg from have group by participant; quit;
02-17-2018 05:23 PM
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;
02-18-2018 02:35 PM
02-18-2018 02:53 PM
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?
02-19-2018 04:07 PM
02-20-2018 11:39 AM
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.
02-17-2018 04:45 PM
You can use PROC MEANS as illustrated here:
Or you can add it in to your overall data set as illustrated here:
And there are video tutorials here if you prefer that: