## Counting number of observations with certain value

Solved
Occasional Contributor
Posts: 12

# Counting number of observations with certain value

Hello I am looking to be able to count the number of observations with values < 25 and also those > 25 but < 30. I have read some other solved questions but haven't been able to produce a successful code. Thanks for any help!

Accepted Solutions
Solution
‎10-30-2017 02:48 PM
Super User
Posts: 6,939

## Re: Counting number of observations with certain value

I would use a format, to account for all categories:

proc format;

value bmi_cat

low - < 25 = 'Under 25'

25 - < 30 = '25 to under 30'

30 - high = '30+';

run;

proc freq data=have;

tables bmi / missing;

format bmi bmi_cat.;

run;

Regardless of the method that you choose, note that missing values are less than 25.  Make sure you account for them in a way that makes sense to you.

All Replies
Super User
Posts: 10,623

## Re: Counting number of observations with certain value

In proc sql, use the count(*) function and a suitable where condition.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎10-30-2017 02:48 PM
Super User
Posts: 6,939

## Re: Counting number of observations with certain value

I would use a format, to account for all categories:

proc format;

value bmi_cat

low - < 25 = 'Under 25'

25 - < 30 = '25 to under 30'

30 - high = '30+';

run;

proc freq data=have;

tables bmi / missing;

format bmi bmi_cat.;

run;

Regardless of the method that you choose, note that missing values are less than 25.  Make sure you account for them in a way that makes sense to you.

Occasional Contributor
Posts: 12