turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- proc means with some conditions

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-08-2016 01:44 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to fengyuwuzu

01-08-2016 02:42 PM

And for the extremes

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to fengyuwuzu

01-08-2016 01:54 PM

You can use WHERE statements in almost all procs.

proc means blah blah;

WHERE age in (0:100);

...

run;

proc means blah blah;

WHERE age in (0:100);

...

run;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

01-08-2016 02:44 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to fengyuwuzu

01-08-2016 03:35 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to FreelanceReinhard

01-08-2016 04:16 PM

Thank you, you are right. That's why I had many cases excluded in mean calculation.

Solution

01-08-2016
02:47 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to fengyuwuzu

01-08-2016 02:42 PM

And for the extremes

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;