BookmarkSubscribeRSS Feed
klovewalk
Calcite | Level 5

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

5 REPLIES 5
Cynthia_sas
SAS Super FREQ

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

klovewalk
Calcite | Level 5

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

Cynthia_sas
SAS Super FREQ

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;  

Doc: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146737.htm

 

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


output_means.jpg
vsandoval6
Calcite | Level 5

I'm analyzing the DeathCause and AgeAtDeath grouped by Status and the question is :

  1.      Are DeathCause and AgeAtDeath ever non-missing when Status=Alive?

This is my response, am I looking at this correct?  I keep getting confused the "non-missing" verbiage

DeathCause and AgeAtDeath are not relative to Status=Alive since the person is Alive so there would be no information to add to the Deathcause and AgeAtDeath categories.  DeathCause and AgeAtDeath would be non-missing at Status=Alive

Kurt_Bremser
Super User

Post your complete(*) question in a new thread of your own.

 

*) Include your code, and the entire log of the failing step. Unless you use one of the SASHELP datasets, post example data in a data step with datalines.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 989 views
  • 5 likes
  • 4 in conversation