BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

37 REPLIES 37
Reeza
Super User

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;

 

Bal23
Lapis Lazuli | Level 10

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

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

Reeza
Super User

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

Bal23
Lapis Lazuli | Level 10

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

 

ballardw
Super User

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.

Bal23
Lapis Lazuli | Level 10

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

ballardw
Super User

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.

Bal23
Lapis Lazuli | Level 10

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

Reeza
Super User
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.
Bal23
Lapis Lazuli | Level 10

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

ballardw
Super User

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.

 

Bal23
Lapis Lazuli | Level 10

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.

 

 

 

Reeza
Super User

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. 

 

Reeza
Super User

@Bal23 wrote:

unfortunately, he

 

 

 


She

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 ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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