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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.