Solved
Contributor
Posts: 32

# Not applicable variable

Hi all! I've a question about a variable when it is not applicable. In my dataset there is a variable for diabetes. Persons with diabetes get a 1 and persons without get a 0. There is also a variable which contains the age of diabetes diagnosis. So only for the diabetes=1 persons there is an age in the diabetes diagnosis variable. The others with a diabetes=0, I give a '999' as in not applicable in the diabetes age variable. The real missings get a dot. But now for calculating the mean age of diabetes diagnosis, SAS takes also the 999 into account. What could I do to take only the 'real' diabetes ages into account in the mean statement and not the 999 values? So that it is treated in the same way as the real missing values with a dot? I want to do this in the MEAN statement and NOT working with IF diabetes=1 THEN .. as it is possible.

Thanks!

Accepted Solutions
Solution
‎11-25-2017 04:52 AM
Super User
Posts: 6,934

## Re: Not applicable variable

Instead of using 999 to indicate not applicable, you would be better off using a special missing value.  For example:

if var = 999 then var = .N ;

That way, you can distinguish .N from . and yet PROC MEANS knows enough to throw both values out of the calculations.

All Replies
PROC Star
Posts: 1,402

## Re: Not applicable variable

[ Edited ]

What does your code look like now?

A simple where statement may solve your problem.

Solution
‎11-25-2017 04:52 AM
Super User
Posts: 6,934

## Re: Not applicable variable

Instead of using 999 to indicate not applicable, you would be better off using a special missing value.  For example:

if var = 999 then var = .N ;

That way, you can distinguish .N from . and yet PROC MEANS knows enough to throw both values out of the calculations.

Contributor
Posts: 32

## Re: Not applicable variable

Okay, I tried this. But then the values of .N are also counted as missing values in PROC MEANS NMISS statement. What can I do to let PROC MEANS know that this is not a 'missing value' and that it also not is taken into acount in the calculations?

Super User
Posts: 6,934

## Re: Not applicable variable

PROC MEANS can't do that.  A value is either missing (and excluded from calculations) or not missing (and included in calculations).  There are no other choices as far as PROC MEANS is concerned.

If you want separate counts, you could use PROC FREQ.  For example:

proc format;

value valid low-high='Valid';

run;

proc freq data=have;

tables var / missing;

format var valid.;

run;

Be sure to include the MISSING option to get separate counts for each type of missing value.

Super User
Posts: 24,012

## Re: Not applicable variable

If the 999 gets excluded entirely from numerator and denominator then use a WHERE.

Where not missing(var);
Posts: 1,270

## Re: Not applicable variable

Hi,

Another way by using proc sql:

proc sql;
select diabetes,mean(age) as mean_age
from have
group by diabetes;
quit;
☑ This topic is solved.