Hi,
I have a large dataset and I want to get the mean of one of the variables when the values of the other variable are in between a particular range.For example,
I want to know the mean AR when 0<TE<0.1 , 0.1<TE<0.2, and so on uptil the 5.90<te<6.0
However, I am not sure how to go about it.
Would appreciate your suggestions.
Or you could do this with a single query:
proc sql;
create table want as
select
0.1 * ceil(TE*10) as TEgroup,
mean(AR) as meanAR
from have
group by calculated TEgroup;
quit;
Here's an easy way to create the groupings:
data want;
set have;
te_group = ceil(10*te);
run;
As long as TE behaves, you will get TE_GROUP with integer values from 1 through 60. Then compute the mean for each group:
proc means data=want;
class te_group;
var somevar;
run;
Or you could do this with a single query:
proc sql;
create table want as
select
0.1 * ceil(TE*10) as TEgroup,
mean(AR) as meanAR
from have
group by calculated TEgroup;
quit;
Thank you PG, it worked just the way I wanted.
Cheers,
AM
Thank you all for the suggestions, were really helpful.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.