Hi guys,
suppose to have the following table:
data DB;
input ID :$20. Resp1 :$20. Resp2 :$20. Resp3 :$20.;
cards;
1 a b .
2 a c .
3 d . .
4 a b f
5 a b .
....
;
Is there a way to get the number of all combinations?
Desired output:
| Combination | Freq |
| ab | 2 |
| ac | 1 |
| d | 1 |
| abf | 1 |
| ...... | ... |
Thank you in advance
I love this kind of question.
EDITED
data DB;
input ID :$20. Resp1 :$20. Resp2 :$20. Resp3 :$20.;
cards;
1 a b .
2 a c .
3 d . .
4 a b f
5 a b .
;
data temp;
set db;
array r{3} $ Resp1-Resp3;
call sortc(of r{*});
do n=1 to dim(r);
if missing(r{n}) then r{n}='09'x;
end;
array x{3};
length combination $ 80;
k=-1;
do i=1 to 2**dim(x);
rc=graycode(k,of x{*});
call missing(combination);
do j=1 to dim(x);
if x{j}=1 then combination=cats(combination,r{j});
end;
if not findc(combination,'09'x) and not missing(combination) then output;
end;
keep combination;
run;
proc freq data=temp noprint;
table combination/out=want ;
run;
I love this kind of question.
EDITED
data DB;
input ID :$20. Resp1 :$20. Resp2 :$20. Resp3 :$20.;
cards;
1 a b .
2 a c .
3 d . .
4 a b f
5 a b .
;
data temp;
set db;
array r{3} $ Resp1-Resp3;
call sortc(of r{*});
do n=1 to dim(r);
if missing(r{n}) then r{n}='09'x;
end;
array x{3};
length combination $ 80;
k=-1;
do i=1 to 2**dim(x);
rc=graycode(k,of x{*});
call missing(combination);
do j=1 to dim(x);
if x{j}=1 then combination=cats(combination,r{j});
end;
if not findc(combination,'09'x) and not missing(combination) then output;
end;
keep combination;
run;
proc freq data=temp noprint;
table combination/out=want ;
run;
A question that might become of interest would be is there a difference in the "combination"
1 a b . 2 a . b
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.