DATA Step, Macro, Functions and more

calculating mean(summary statistics) of different tranches

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

calculating mean(summary statistics) of different tranches

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.


Accepted Solutions
Solution
‎02-23-2018 04:55 PM
Esteemed Advisor
Posts: 5,474

Re: calculating mean(summary statistics) of different tranches

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;
PG

View solution in original post


All Replies
Regular Contributor
Posts: 249

Re: calculating mean(summary statistics) of different tranches

Hi Amalik, you can first create a new variable in the data step using if-else statements to group the TE values into categories. Then, you use the new TE grouping variable to get the mean of AR in proc means. Alternatively, you may create a format for TE variable using proc format and associate the format to the TE variable to get the AR mean by TE groups. HTH.
Super User
Posts: 6,622

Re: calculating mean(summary statistics) of different tranches

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;

Solution
‎02-23-2018 04:55 PM
Esteemed Advisor
Posts: 5,474

Re: calculating mean(summary statistics) of different tranches

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;
PG
Contributor
Posts: 50

Re: calculating mean(summary statistics) of different tranches

Thank you PG, it worked just the way I wanted.

 

Cheers,

AM

Contributor
Posts: 50

Re: calculating mean(summary statistics) of different tranches

Thank you all for the suggestions, were really helpful.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 163 views
  • 2 likes
  • 4 in conversation