DATA Step, Macro, Functions and more

Counting number of observations with certain value

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

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.

View solution in original post


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

Re: Counting number of observations with certain value

Posted in reply to Astounding

this worked thanks so much!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 171 views
  • 0 likes
  • 3 in conversation