BookmarkSubscribeRSS Feed
ebonfil89
Calcite | Level 5

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

 

9 REPLIES 9
novinosrin
Tourmaline | Level 20

do you mean -

proc sql;
create table want as
select participant, mean(sedtime) as avg
from have
group by participant;
quit;
novinosrin
Tourmaline | Level 20
proc summary data=have nway;
class participant;
var sedtime;
output out=want(drop=_:) mean=/autoname;
run;
ebonfil89
Calcite | Level 5

Thank you for the information. In this procedure, what is the new variable that was created? 

novinosrin
Tourmaline | Level 20

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:

participantSedtime_Mean
13
23
34.333333333
ebonfil89
Calcite | Level 5
Thank you so much, option two worked for me.

Proc means data = WORK.IMPORT noprint nway;
class PQ_Study_ID_Unique;
output out = avg_values mean (sed) = ave_sed;
run;

Proc sort data = work.import out = sort;
by PQ_Study_ID_Unique;
run;

data sort_sed;
merge sort avg_values;
run;

proc print data = sort_sed;
run;
Reeza
Super User

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
Calcite | Level 5
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.
Reeza
Super User

@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. 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 2135 views
  • 1 like
  • 3 in conversation