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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1608 views
  • 1 like
  • 3 in conversation