## proc means with some conditions

Solved
Super Contributor
Posts: 328

# proc means with some conditions

I realized that in my data set the age variables are in the range [-88, +137], so I want to get rid of those unreasable ages.

I can subset the data set using if condition. But I wonder if there is a way that I can calculate the means, say, in (0,100) range, in the proc means procedure?

And is there a way to count how many cases with age <0 or age >100?

Thank you.

Accepted Solutions
Solution
‎01-08-2016 02:47 PM
Super User
Posts: 13,583

## Re: proc means with some conditions

And for the extremes

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;

All Replies
Super User
Posts: 23,773

## Re: proc means with some conditions

You can use WHERE statements in almost all procs.

proc means blah blah;
WHERE age in (0:100);
...
run;
Super Contributor
Posts: 328

## Re: proc means with some conditions

Thank you very much.

I used where age >0 and age <100; and it worked.

but when I use where age in (0:100) I had many cases not included. not sure why.

Posts: 1,256

## Re: proc means with some conditions

Please note that the notation (0:100) stands for the set of integers {0, 1, 2, ..., 99, 100}. So, for example age=12.3 does not satisfy the condition age in (0:100), although it satisfies 0<age<100.

Are you sure that all your age values are integers? You could check this with the following step:

``````proc freq data=yourdata;
where age ne intz(age);
tables age;
run;``````

If the output of the above PROC FREQ contains any integer value of AGE, then you've encountered a numeric representation issue and you may want to round your AGE values, e.g. like age=round(age, 1e-9).

Example:

``````data ttt;
age=9.9/3.3; /* should equal 3, mathematically */
run;

proc freq data=ttt;
where age ne intz(age);
tables age; /* looks like 3, but is not 3! */
run;
``````

Super Contributor
Posts: 328

## Re: proc means with some conditions

Thank you, you are right. That's why I had many cases excluded in mean calculation.
Solution
‎01-08-2016 02:47 PM
Super User
Posts: 13,583

## Re: proc means with some conditions

And for the extremes

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;

🔒 This topic is solved and locked.