BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

And for the extremes

 

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;

View solution in original post

5 REPLIES 5
Reeza
Super User
You can use WHERE statements in almost all procs.

proc means blah blah;
WHERE age in (0:100);
...
run;
fengyuwuzu
Pyrite | Level 9

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.

FreelanceReinh
Jade | Level 19

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;

 

fengyuwuzu
Pyrite | Level 9
Thank you, you are right. That's why I had many cases excluded in mean calculation.
ballardw
Super User

And for the extremes

 

proc freq data= yourdata;

where age < 0 or age>100;

tables age;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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