Programming the statistical procedures from SAS

How to calculate relative risk, and 95%CI

Accepted Solution Solved
Reply
Super Contributor
Posts: 331
Accepted Solution

How to calculate relative risk, and 95%CI

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
Grand Advisor
Posts: 16,933

Re: How to calculate relative risk, and 95%CI

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.

View solution in original post


All Replies
Grand Advisor
Posts: 16,933

Re: How to calculate relative risk, and 95%CI

Why do you want a macro or array? 

 

Proc freq can calculate relative risk.

https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_freq_sect02...

 

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;

 

Super Contributor
Posts: 331

Re: How to calculate relative risk, and 95%CI

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

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

Grand Advisor
Posts: 16,933

Re: How to calculate relative risk, and 95%CI

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

Super Contributor
Posts: 331

Re: How to calculate relative risk, and 95%CI

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

 

Grand Advisor
Posts: 10,075

Re: How to calculate relative risk, and 95%CI

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.

Super Contributor
Posts: 331

Re: How to calculate relative risk, and 95%CI

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

Grand Advisor
Posts: 10,075

Re: How to calculate relative risk, and 95%CI

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.

Super Contributor
Posts: 331

Re: How to calculate relative risk, and 95%CI

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

Grand Advisor
Posts: 16,933

Re: How to calculate relative risk, and 95%CI

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.
Super Contributor
Posts: 331

Re: How to calculate relative risk, and 95%CI

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

Grand Advisor
Posts: 10,075

Re: How to calculate relative risk, and 95%CI

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.

 

Super Contributor
Posts: 331

Re: How to calculate relative risk, and 95%CI

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.

 

 

 

Grand Advisor
Posts: 16,933

Re: How to calculate relative risk, and 95%CI

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. 

 

Grand Advisor
Posts: 16,933

Re: How to calculate relative risk, and 95%CI


wenling wrote:

unfortunately, he

 

 

 


She

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 37 replies
  • 649 views
  • 4 likes
  • 3 in conversation