There might be a better, more efficient way of doing this, but here is my initial shot at a program which moves through all the combinations to find joint probabilities:
[pre]
data test;
input id $ cough headache vomiting;
datalines;
1 1 1 0
2 0 1 0
3 0 0 0
4 1 1 0
;
run;
proc sql noprint;
select distinct name into: conditions separated by '" "'
from sashelp.vcolumn
where libname = 'WORK' and memname = 'TEST' and upcase(name) ne 'ID';
select count(*) into: num_conditions
from sashelp.vcolumn
where libname = 'WORK' and memname = 'TEST' and upcase(name) ne 'ID';
quit;
data temp(drop=n ncomb j rc);
array condition[&num_conditions] $20 ("&conditions");
n=dim(condition);
do k=1 to dim(condition);
ncomb=comb(n,k);
do j=1 to ncomb+1;
rc=lexcomb(j, k, of condition
);
if rc<0 then leave;
output;
end;
end;
run;
data _null_;
length combinations $ 200;
set temp end=last;
array condition{*} condition:;
do j=1 to dim(condition);
if j>k then condition{j} = ' ';
end;
combinations=catx(' and ', of condition:);
i+1;
call symput(cats("condition",i), combinations);
if last then call symput('nobs', i);
run;
data probabilities;
length conditions $ 200 prob 8;
if 0 then output;;
run;
%macro probabilities;
proc sql;
%do i=1 %to &nobs;
insert into probabilities(conditions, prob)
select "&&&condition&i", sum(&&&condition&i)/count(*)
from test;
%end;
quit;
%mend;
%probabilities
proc print data=probabilities;
run;
[/pre]
Message was edited by: polingjw
Modified array declaration in the data _null_ step. Previously used condition1-condition3.