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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.