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