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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

What does your code look like now?

 

A simple where statement may solve your problem.

Astounding
PROC Star

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.

hovliza
Obsidian | Level 7

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?

Astounding
PROC Star

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.

Reeza
Super User

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

 

Where not missing(var);
stat_sas
Ammonite | Level 13

Hi,

 

Another way by using proc sql:

 

proc sql;
select diabetes,mean(age) as mean_age
from have
group by diabetes;
quit;

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
  • 6 replies
  • 1587 views
  • 4 likes
  • 5 in conversation