Hi, I currently have 2 tables that I produce via proc tabulates using the below code:
title 'TableA'; proc tabulate data = Example out = Numerator; class GroupA GroupB GroupC GroupD ap_month; var count one; table GroupA=''*GroupB=''*GroupC=''*GroupD=''*sum=''*(count*f=comma14.0),month /nocellmerge; run; title 'TableB'; proc tabulate data = Example out = Denominator; class GroupA GroupB GroupC GroupD month; var count one; table GroupA=''*GroupB=''*GroupC=''*GroupD=''*sum=''*(one*f=comma14.0),month /nocellmerge; run;
The tables look like this:
by dividing through one another you get probabilities and create a probability matrix.
So what the table is basically saying is, if groupA=1 and GroupB,C,D=0 then probabilities in each month are the top line of the first table divided by the top line of bottom table.
I would like to create some code that does this dividing to create the same table with probabilities without having to manually divide one table through another in excel.
Does anyone know if this is possible?
NB. the "count variable" represents whether someone has had a certain event (this is what the probabilities relate to - the probabilities of having this event) and the variable "one" is a constant variable that =1 for all observations in the data. If people are in different groups then the probability of having the event is different.
Thanks
Never mind, I've worked it out! Using the output from the above proc tabulates you need to run the following code:
data Merged;
merge TableA(drop = _TYPE_ _PAGE_ _TABLE_)
TableB(drop = _TYPE_ _PAGE_ _TABLE_);
by GroupA GroupB GroupC GroupD Month;
Probability=Count_Sum/One_Sum;
run;
proc report data=Merged;
column GroupA GroupB GroupC GroupD month,(Probability);
define Month / Across;
define GroupA / Group;
define GroupB / Group;
define GroupC / Group;
define GroupD / Group;
define Probability / sum;
run;
Never mind, I've worked it out! Using the output from the above proc tabulates you need to run the following code:
data Merged;
merge TableA(drop = _TYPE_ _PAGE_ _TABLE_)
TableB(drop = _TYPE_ _PAGE_ _TABLE_);
by GroupA GroupB GroupC GroupD Month;
Probability=Count_Sum/One_Sum;
run;
proc report data=Merged;
column GroupA GroupB GroupC GroupD month,(Probability);
define Month / Across;
define GroupA / Group;
define GroupB / Group;
define GroupC / Group;
define GroupD / Group;
define Probability / sum;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.