a********a 发帖数: 346 | 1 I have a 5 variable q1, q2, q3, q4, q5. All of these variables are Yes, No
questions. How can I find the id that answered exact two Y's for these 5
variables? As there are 10 combinations for these 5 variables, if I do not
want to write if (q1='Y' and q2='Y' ) or....., how can I do? Thanks
id q1 q2 q3 q4 q5
1 Y N Y N Y
2 Y Y N N N
3 Y N N N N
.... | b**********i 发帖数: 1059 | 2 change to 1, 0 and add together?
【在 a********a 的大作中提到】 : I have a 5 variable q1, q2, q3, q4, q5. All of these variables are Yes, No : questions. How can I find the id that answered exact two Y's for these 5 : variables? As there are 10 combinations for these 5 variables, if I do not : want to write if (q1='Y' and q2='Y' ) or....., how can I do? Thanks : id q1 q2 q3 q4 q5 : 1 Y N Y N Y : 2 Y Y N N N : 3 Y N N N N : ....
| b**s 发帖数: 9 | 3
data dd; set dd;
qs=compress(q1||q2||q3||q4||q5);
counter=count(qs,'Y');
run;
or use array
【在 a********a 的大作中提到】 : I have a 5 variable q1, q2, q3, q4, q5. All of these variables are Yes, No : questions. How can I find the id that answered exact two Y's for these 5 : variables? As there are 10 combinations for these 5 variables, if I do not : want to write if (q1='Y' and q2='Y' ) or....., how can I do? Thanks : id q1 q2 q3 q4 q5 : 1 Y N Y N Y : 2 Y Y N N N : 3 Y N N N N : ....
| p********a 发帖数: 5352 | 4 data b;
set a;
where sum((q1='Y'),(q2='Y'), (q3='Y'),(q4='Y'),(q5='Y'))=2;
run; | a********a 发帖数: 346 | 5 great idea, thanks guys. | y****n 发帖数: 46 | 6 data temp;
length q1-q5 $1;
input id q1 q2 q3 q4 q5;
cards;
1 Y N Y N Y
2 Y Y N N N
3 Y N N N N
;
run;
data new;
array qq(5) $ q1-q5;
array xx(5) x1-x5;
set temp;
do i=1 to 5;
xx(i)=input(qq(i),ct.);
end;
if sum(of x1-x5)=2 then output;
keep id q1-q5;
run; | y****n 发帖数: 46 | 7 proc format;
invalue ct
'Y'=1
'N'=0;
run;
data temp;
length q1-q5 $1;
input id q1 q2 q3 q4 q5;
cards;
1 Y N Y N Y
2 Y Y N N N
3 Y N N N N
;
run;
data new;
array qq(5) $ q1-q5;
array xx(5) x1-x5;
set temp;
do i=1 to 5;
xx(i)=input(qq(i),ct.);
end;
if sum(of x1-x5)=2 then output;
keep id q1-q5;
run; |
|