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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.