Hi
| Suppose you have to at least one categories out of 10 | |||||||||||
| category name | |||||||||||
| X1 | multiple choice may be possible | ||||||||||
| X2 | |||||||||||
| X3 | |||||||||||
| X4 | |||||||||||
| X5 | |||||||||||
| X6 | |||||||||||
| X7 | |||||||||||
| X8 | |||||||||||
| X9 | |||||||||||
| X10 | |||||||||||
| so data will be resprented as below | |||||||||||
| Name | X1 | X2 | X3 | X4 | X5 | X6 | X7 | X8 | X9 | X10 | total cat |
| A | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 4 |
| B | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 3 |
| C | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 5 |
| D | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 4 |
| E | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 2 |
| F | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| G | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 |
| H | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 |
| I | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 3 |
| J | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
| then output should be come this way | |||||||||||
| name of cater | |||||||||||
| X1 | X2 | X3 | X4 | 0 | |||||||
| X3 | X8 | X9 | 0 | 0 | |||||||
| X1 | X2 | X3 | X8 | X9 | |||||||
| X1 | X2 | X8 | X9 | 0 | |||||||
| X2 | X9 | 0 | 0 | 0 | |||||||
| X8 | 0 | 0 | 0 | 0 | |||||||
| X3 | 0 | 0 | 0 | 0 | |||||||
| X1 | X10 | 0 | 0 | 0 | |||||||
| X2 | X3 | X10 | 0 | 0 | |||||||
| X1 | X2 | 0 | 0 | 0 | |||||||
Regards
Here is one way:
data have;
input Name $ X1-X10 total_cat;
cards;
A 1 1 1 1 0 0 0 0 0 0 4
B 0 0 1 0 0 0 0 1 1 0 3
C 1 1 1 0 0 0 0 1 1 0 5
D 1 1 0 0 0 0 0 1 1 0 4
E 0 1 0 0 0 0 0 0 1 0 2
F 0 0 0 0 0 0 0 1 0 0 1
G 0 0 1 0 0 0 0 0 0 1 2
H 1 0 0 0 0 0 0 0 0 1 2
I 0 1 1 0 0 0 0 0 0 1 3
J 1 1 0 0 0 0 0 0 0 0 2
;
proc sql noprint;
select distinct max(total_cat)
into :maxcat
from have
;
quit;
data want (keep=name used:);
set have;
array selected(*) x1-x10;
array used(&maxcat.) $2.;
j=0;
do i=1 to &maxcat.;
used(i)='0';
end;
do i=1 to dim(selected);
if selected(i) eq 1 then do;
j+1;
used(j)=vname(selected(i));
end;
end;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.