DATA Step, Macro, Functions and more

proc means with some conditions

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

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: 10,516

Re: proc means with some conditions

And for the extremes

 

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;

View solution in original post


All Replies
Super User
Posts: 17,868

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: 312

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.

Trusted Advisor
Posts: 1,115

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: 312

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: 10,516

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.

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

Discussion stats
  • 5 replies
  • 290 views
  • 3 likes
  • 4 in conversation