turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- How to calculate relative risk, and 95%CI

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 11:18 AM

I would like to know how to use SAS macro/array to calculate relative risk. It has 5 IDs, I need to calculate lower bound and upper bound.

Would any of you present me a code or a simiar example?

Thanks.

Accepted Solutions

Solution

01-19-2016
08:17 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-18-2016 11:10 AM

If first.mygroup identifies that record. Try adding the condition in an IF statement, make sure it goes in the appropriate location (ie after the calculation).

Give it a try and if you have difficulties post the error with your code.

Otherwise I think your original question is now answered and please mark this question answered.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 11:23 AM

Why do you want a macro or array?

Proc freq can calculate relative risk.

```
proc format;
value ExpFmt 1='High Cholesterol Diet'
0='Low Cholesterol Diet';
value RspFmt 1='Yes'
0='No';
run;
data FatComp;
input Exposure Response Count;
label Response='Heart Disease';
datalines;
0 0 6
0 1 2
1 0 4
1 1 11
;
proc sort data=FatComp;
by descending Exposure descending Response;
run;
proc freq data=FatComp order=data;
format Exposure ExpFmt. Response RspFmt.;
tables Exposure*Response / chisq relrisk;
exact pchi or;
weight Count;
title 'Case-Control Study of High Fat/Cholesterol Diet';
run;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 11:44 AM

Thanks. Those are varibles that have more than two levels of catogory. (>2)

So I am looking for a code that can do this.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 11:50 AM

Please provide sample data, expected output and some details surrounding your question.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 12:00 PM

agegroup <10 10-20 20-30 >30

the risk of surgery 2.37 2.4 2.8 3.2 (%)

now I need to caculate the crude relatve risk, using <10 agegroup as a reference (1.00)

I also want to caculate same things among different communities (up to five communities). This is why I want to use array and/or macro

Thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 01:24 PM

You may need to provide additional information about how your current SAS data set is structured. For example, you give a percent which seem to be your current value. But what was the actual size of the sample that the percent was calculated from? Since you are asking for "upper and lower bounds" I am assuming that is a confidence interval you are requesting and the calculation for that will require the original sample size.

Can your print a few rows of your data to show us what it looks like? You may need restructuring to calculate the risks and confidence intervals.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 01:29 PM

It is about 200,000 obs. For some age groups, it has 50,000. Others have more.

sorry, the data cannot be printed out. I just list an example that is very similar to my original data.

I would like to see whether there is any reference. I read some books and articles showing examples on variables with two catogories. But mine is over two. So it will be beneficial if there is code for three catogories or over three.

Thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 02:13 PM

You need to show us what your data looks like. Dummy values are fine but the structure of current data set is important.

Does each record relate to a single person? Is that person in the data more than once? If a person is in the data more than once which record is to be used for the relative risk calculation.

You can get ODDS ratios between a base group and other groups using Proc Logistic (and others).

If you are looking at age as a contributor to specific outcome you might want to look at a regression model which would yield a change in likelihood per year of age.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 02:30 PM

I do not quite understand what "structure" you mean here.

In my dataset, some people have multiple records. But I have already disingushi this by using sort by their ID

relative risk is simply the rate I put and calculated by the total number of people. Then I need to calculate its related 95%CI.

I want to have a macro or array code to calculate since it has multiple subgroups.

RR= count of patients who had surgery/total people

lower CI=exp(ln(RR-1.96???? (formula should be available available, but I cannot find code)

so it really does not matter how much my data looks like, I am looking for a sample code to deal with data with >2 catogories

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 03:40 PM

Of course it matters how your data is. For starters, is your data already in counts, so can you divide two variables for RR? Or do you have individual level information and need to calculate the # of patients who had surgery and the total number?

How are your groups defined as well, is there a variable that defines your groups or multiple variables that have information for each group?

Typically subgroup analysis in SAS is via BY group processing, not macro or array. And sometimes transposing your data makes your analysis simpler.

If you know exactly what you want and need help converting that to a macro or array please post what you have and someone can help from there.

Otherwise vague problem descriptions get vague answers.

How are your groups defined as well, is there a variable that defines your groups or multiple variables that have information for each group?

Typically subgroup analysis in SAS is via BY group processing, not macro or array. And sometimes transposing your data makes your analysis simpler.

If you know exactly what you want and need help converting that to a macro or array please post what you have and someone can help from there.

Otherwise vague problem descriptions get vague answers.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 03:58 PM

my data is not already in counts. First, I used SQL to put those different datasets together (different communities). Then, I use proc freq to calculte counts. Then, I calculate RR.

I have to use excel to calculate, one by one, which is very slow. So I am thinking whether I can speed up with macro code

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 04:06 PM

If a person is in your data more than once do you count them as a person (once for the entire data set) or each time they appear? How your result is interpreted depends on knowing that.

How is a person treated in the counts if a person is in the data once in one age group without the surgery but then has the surgery when in another age group and then appears later in yet another age group?

I think you may be at a point where you need to go back to what the research question that is being asked is defined to get clarification on how to treat your data, probably such that a person only occurs once in the analysis. At this point, I would not provide code on just how to do multiple chi-sq tests as I would not want to be associated with any result.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 04:47 PM

count only once

the agegroup is classfied at the beginning of research, no more agegroup variable later

we only analyze the patient once;

Just as the first one who provided code for me---unfortunately, he provided a sample code for variables with two categories----that is same as what I have read and learned online. I need, in stead, a sample code for variables with more than two catogories, like age groups.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 08:03 PM

Are you sure you need relative risk? With multiple levels I'm more used to seeing odds ratio.

You usually need case/control scenarios for relative risk.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2016 08:05 PM

wenling wrote:

unfortunately, he

She