BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
richart
Fluorite | Level 6

Hello,

 

I have approximately 20 subjects and 30 questions (True or False responses). My goal is to tabulate a respondent-by-respondent matrix, in which each cell would have the number of identical responses per individual. Something like this:


sas1.PNG
While right now I have something like this, with respondents as rows and questions as columns:

 

sas2.PNG

 

I was going to try and use if-then statements to calculate the agreeance between each combination of respondent, by transposing the data and doing something like "if var1=var2 then agreeance_12=1; else aggreance_12=0" but this would obviously take a very long time. I would appreciate anyone's help!  

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

proc distance gets you close ...

 

data have;
input subj $ (res1-res5) (:$1.);
datalines;
1 T F T T F 
2 T F F F T
3 F T F T T 
4 F F F F T
;

proc distance data=have out=want method=match shape=square;
id subj;
var nominal (res1-res5);
run;

proc print data=want noobs; run;
                        subj     _1     _2     _3     _4

                         1      1.0    0.4    0.2    0.2
                         2      0.4    1.0    0.4    0.8
                         3      0.2    0.4    1.0    0.6
                         4      0.2    0.8    0.6    1.0
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

proc distance gets you close ...

 

data have;
input subj $ (res1-res5) (:$1.);
datalines;
1 T F T T F 
2 T F F F T
3 F T F T T 
4 F F F F T
;

proc distance data=have out=want method=match shape=square;
id subj;
var nominal (res1-res5);
run;

proc print data=want noobs; run;
                        subj     _1     _2     _3     _4

                         1      1.0    0.4    0.2    0.2
                         2      0.4    1.0    0.4    0.8
                         3      0.2    0.4    1.0    0.6
                         4      0.2    0.8    0.6    1.0
PG
Ksharp
Super User
data have;
input subj $ (res1-res5) (:$1.);
datalines;
1 T F T T F 
2 T F F F T
3 F T F T T 
4 F F F F T
;
data temp;
 set have;
 array x{*} res:;
 do i=1 to dim(x);
   do j=i+1 to dim(x);
    if x{i}=x{j} then do;a=vname(x{i});b=vname(x{j});output; end;
   end;
 end;
keep a b;
run;
proc freq data=temp noprint;
table a*b/out=temp1;
run;
data temp2(index=(a));
 set temp1;
 output;
 temp=a;a=b;b=temp;output;
 drop temp;
run;

proc transpose data=temp2 out=temp3(drop=_:);
by a;
id b;
var count;
run;
proc sql noprint;
select a into : list separated by ' ' from temp3;
quit;
data temp4;
 retain a &list;
 set temp3;
run;
proc stdize data=temp4 out=want missing=0 reponly;
run;

Assuming I understand your question .

richart
Fluorite | Level 6

This works perfectly as well. Thanks!

ballardw
Super User

@richart wrote:

Hello,

 

I have approximately 20 subjects and 30 questions (True or False responses). My goal is to tabulate a respondent-by-respondent matrix, in which each cell would have the number of identical responses per individual. Something like this:


sas1.PNG

 

!  


So what does 1,2, 3 as column header or the 13 mean in first row? I am really not sure what you are actually counting. Define "identical response per individual". Perhaps if you provided a small example such as a data step with 3 individuals, 4 questions and what the result matrix looks like.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 634 views
  • 0 likes
  • 4 in conversation