Good afternoon, I am sure there is a more efficient way to do this so please don't hesitate to make suggestions on that aspect, but I am trying to compare the question/answer values by male and female to see if they are comparable. To do this, I concatenate the question and answer values onto one line, separate the table into one for male and one for female and then create a 'matched' table and 'unmatched' table using merge. The problem is, when I do this, one ID is not showing up in either table. PRODUCT_ID 5 is not in either table. Can anyone tell me why? It should be included in the matched table. The result should be: Matched: PRODUCT_ID's 1,2,4 and 5. Unmatched: PRODUCT_ID's 3,6. Here is the code: data have_1;
input product_id gender$ article$ question_id answer_id;
datalines;
1 M SHIRT 1 1
1 M SHIRT 2 1
1 M SHIRT 3 1
2 F SHIRT 1 1
2 F SHIRT 2 1
2 F SHIRT 3 1
3 M SHIRT 1 1
3 M SHIRT 2 2
3 M SHIRT 3 2
4 F PANTS 1 1
4 F PANTS 2 1
4 F PANTS 3 1
5 F PANTS 1 1
5 F PANTS 2 1
5 F PANTS 3 1
6 M PANTS 1 2
6 M PANTS 2 2
6 M PANTS 3 2
run;
data have_2;
length answer_values $1000.;
length question_values $1000.;
do until (last.product_id);
set have_1;
by product_id notsorted;
answer_values = catx(',',answer_values,answer_id);
question_values = catx(',',question_values,question_id);
end;
drop answer_id question_id;
run;
proc sql;
create table mens as
select *
from have_2
where GENDER = 'M'
order by question_values, answer_values;
quit;
proc sql;
create table womens as
select *
from data_2
where GENDER = 'F'
order by question_values, answer_values;
quit;
data test_matched test_unmatched;
merge womens (in = a) mens (in = b);
by question_values answer_values;
if a and b then output test_matched;
else output test_unmatched;
run; I'm using SAS 9.4. Any insight would be greatly appreciated.
... View more