## in need of help

Occasional Contributor
Posts: 6

# in need of help

I was given the following instructions: Deaths from heart disease comprise the following causes : I00-I09, I11, I13, I20-I51. How many males and females died from heart disease and what was the mean and median age at death for both genders

So I tried the following but am getting errors. Can you assist? Thanks.

PROC FREQ DATA=epi2.heartdis;

table cau*gen;

where cau in ('I00', 'I01', 'I02', 'I03',

'I04', 'I05', 'I06', 'I07', 'I08','I09') and cau ('I11')

and cau ('I13')and ('I20'<cau<'I51');

run

SAS Super FREQ
Posts: 9,371

## Re: in need of help

Hi:

SASHELP.HEART has similar variables, called DEATHCAUSE, SEX and AGEATDEATH. To find out the mean and median ages for each gender and cause of death, I would use PROC MEANS, not PROC FREQ. Something like:

proc means data=sashelp.heart n mean median;

class deathcause sex;

var ageatdeath;

run;

You can use a WHERE statement with PROC MEANS and whether the syntax of your WHERE statement is correct, would depend on your data. For example, does an observation only have 1 value for CAU?? In your WHERE statement, would it be possible for an observation to have a CAU value of 'I06' AND 'I13'??? I'm not sure that your use of the AND operator is what you want, I was envisioning a WHERE statment closer to:

where

(cau in ('I00', 'I01', 'I02', 'I03','I04', 'I05', 'I06', 'I07', 'I08','I09','I11', 'I13'))

or

(cau between 'I20' and 'I51');

But, you will have to test the WHERE statement on your data. I do believe that you will come closer to getting the mean and median age at death analysis if you use PROC MEANS.

cynthia

Occasional Contributor
Posts: 6

## in need of help

Thank you. Was just wondering what does the class statement do. And also I'm still having some trouble with the where statement. But an observation only has 1 value for CAU. thanks again.

Keddra

SAS Super FREQ
Posts: 9,371

## Re: in need of help

Hi,

The CLASS statement tells PROC MEANS to treat SEX and DEATHCAUSE as categories or groups and to break down the analysis based on those groups. You'll have to run the code to see the default output. (I haven't quite mastered posting output. I'll try to post a screen shot as an attachment).

If you wanted a further breakdown of the mean and median AGEATDEATH for only SEX or only DEATHCAUSE or those single tables in addition to the table for the combination of CLASS variables, then you could add a TYPES statement to your code, which would tell PROC MEANS what combination of CLASS variables you wanted to see. So if you wanted to see all the possible combinations of tables (you can actually use the TYPES or the WAYS statement to control interaction of the CLASS variables):

types deathcause sex deathcause*sex;

Your WHERE statement is limiting the rows or observations available to PROC MEANS to process. So if your observations can only have 1 value for the CAU variable, then you would want all your tests to use the OR operator. Coding this:

where ageatdeath in (59, 67, 72);

is the same as coding:

where ageatdeath = 59 or ageatdeath=67 or ageatdeath=72;

And, since you don't want to type all the codes in the series from I20-I51, using BETWEEN will allow you to select from among those CAU values, too, as if you had coded them as:

where cau ='I20' or cau='I21' or cau='I22' .... or cau='I51';

is the same as

where cau in ('I20','I21', 'I22', .... 'I51');

and the same as

where cau between 'I20' and 'I51';

the AND, when used with BETWEEN means that the series I20-I51 will be treated logically as you want. All the rest of your major conditions should use an OR operator. So, if you wanted to have a complex condition (not listing all of the values), something like this:

where (cau in ('I01','I03', 'I05', 'I13'))

OR

(cau between 'I20' and 'I51');

would tell the WHERE processor to see whether the obs value for CAU was found in the IN list OR see whether the obs value for CAU fell into the series defined by the BETWEEN condition.

Since an obs can only have 1 value for CAU, you would not get correct results if you coded your complex condition as:

where (cau in ('I01','I03', 'I05', 'I13'))

AND   /* not correct logical operator */

(cau between 'I20' and 'I51');

I'd recommend getting the code working for the IN group of CAU values, then after you have the PROC MEANS the way you want for that group, modify your WHERE statement to include second condition, using the correct logical operator.

cynthia

added attachment of LISTING output from PROC MEANS

Discussion stats
• 3 replies
• 169 views
• 5 likes
• 2 in conversation