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?
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.
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;
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
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.
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.
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.
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
01-13-2016 03:40 PM
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
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.
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.
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.
Need further help from the community? Please ask a new question.