BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amalik
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

5 REPLIES 5
Miracle
Barite | Level 11
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.
Astounding
PROC Star

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;

PGStats
Opal | Level 21

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
Amalik
Calcite | Level 5

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

 

Cheers,

AM

Amalik
Calcite | Level 5

Thank you all for the suggestions, were really helpful.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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