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

Hi all,

         Thank you in advance! I have a dataset with multiple (6) grader responses. I need to create flag variables based on these responses:

1- One flagged variable if all responses match

2- One flagged variable if all except one response match

3- One flag for no response matching (not 1 or 2)

 

I have trouble creating the flag for 2 -- how do I find responses where all except one match?

 

Here is a sample dataset:

 

num rater1 rater2 rater3 rater4 rater5 rater6  Flag2
Pt1         4         4        4          4        4      4       0

Pt2         3         4        4          4        4      4       1

Pt3         1         2        3          3        2      1       0

Pt4         1         2         1         1         1     1       1

 

How do I create the 'Flag2' variable which flags any observations where all responses except one match between raters?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Reframing your logic:

 

  • Flag1 = Max of series = Min of series - all are the same
  • Flag2 = Max of series is repeated 5 times or Min of series is repeated 5 times. Can switch 5 to DIM(of rater(*))-1 to be more dynamic. 
  • Flag3 = Flag1=0 & Flag2 = 0
data have;
input num $ rater1 rater2 rater3 rater4 rater5 rater6  Flag2;
cards;
Pt1         4         4        4          4        4      4       0
Pt2         3         4        4          4        4      4       1
Pt3         1         2        3          3        2      1       0
Pt4         1         2         1         1         1     1       1
;;;;
run;

data want;
set have;
array rater(6) rater1-rater6;

flag1 = max(of rater(*)) = min(of rater(*));

flag_check = flag1=0 and 
(countc(catx(",", of rater(*)), max(of rater(*))) = 5 or
countc(catx(",", of rater(*)), min(of rater(*))) = 5);

flag3 = flag1=0 & flag2=0;

run;

Here's the more traditional version using IF/THEN. 

data want;
set have;
array rater(6) rater1-rater6;

if max(of rater(*)) = min(of rater(*)) then flag1=1; else flag1=0;

if flag1=0 and 
(countc(catx(",", of rater(*)), max(of rater(*))) = (Dim(rater)-1) or
countc(catx(",", of rater(*)), min(of rater(*))) = (dim(rater)-1)) then flag2=1;
else flag2=0;

if flag1=0 and flag2=0 then flag3 = 1;
else flag3=0;



run;

@Abishekaa wrote:

Hi all,

         Thank you in advance! I have a dataset with multiple (6) grader responses. I need to create flag variables based on these responses:

1- One flagged variable if all responses match

2- One flagged variable if all except one response match

3- One flag for no response matching (not 1 or 2)

 

I have trouble creating the flag for 2 -- how do I find responses where all except one match?

 

Here is a sample dataset:

 

num rater1 rater2 rater3 rater4 rater5 rater6  Flag2
Pt1         4         4        4          4        4      4       0

Pt2         3         4        4          4        4      4       1

Pt3         1         2        3          3        2      1       0

Pt4         1         2         1         1         1     1       1

 

How do I create the 'Flag2' variable which flags any observations where all responses except one match between raters?

 

 

 


 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Reframing your logic:

 

  • Flag1 = Max of series = Min of series - all are the same
  • Flag2 = Max of series is repeated 5 times or Min of series is repeated 5 times. Can switch 5 to DIM(of rater(*))-1 to be more dynamic. 
  • Flag3 = Flag1=0 & Flag2 = 0
data have;
input num $ rater1 rater2 rater3 rater4 rater5 rater6  Flag2;
cards;
Pt1         4         4        4          4        4      4       0
Pt2         3         4        4          4        4      4       1
Pt3         1         2        3          3        2      1       0
Pt4         1         2         1         1         1     1       1
;;;;
run;

data want;
set have;
array rater(6) rater1-rater6;

flag1 = max(of rater(*)) = min(of rater(*));

flag_check = flag1=0 and 
(countc(catx(",", of rater(*)), max(of rater(*))) = 5 or
countc(catx(",", of rater(*)), min(of rater(*))) = 5);

flag3 = flag1=0 & flag2=0;

run;

Here's the more traditional version using IF/THEN. 

data want;
set have;
array rater(6) rater1-rater6;

if max(of rater(*)) = min(of rater(*)) then flag1=1; else flag1=0;

if flag1=0 and 
(countc(catx(",", of rater(*)), max(of rater(*))) = (Dim(rater)-1) or
countc(catx(",", of rater(*)), min(of rater(*))) = (dim(rater)-1)) then flag2=1;
else flag2=0;

if flag1=0 and flag2=0 then flag3 = 1;
else flag3=0;



run;

@Abishekaa wrote:

Hi all,

         Thank you in advance! I have a dataset with multiple (6) grader responses. I need to create flag variables based on these responses:

1- One flagged variable if all responses match

2- One flagged variable if all except one response match

3- One flag for no response matching (not 1 or 2)

 

I have trouble creating the flag for 2 -- how do I find responses where all except one match?

 

Here is a sample dataset:

 

num rater1 rater2 rater3 rater4 rater5 rater6  Flag2
Pt1         4         4        4          4        4      4       0

Pt2         3         4        4          4        4      4       1

Pt3         1         2        3          3        2      1       0

Pt4         1         2         1         1         1     1       1

 

How do I create the 'Flag2' variable which flags any observations where all responses except one match between raters?

 

 

 


 

 

Abishekaa
Obsidian | Level 7

Hi Reeza,

                 Thanks so much! Could you be kind enough to explain how this flag could be created if the data are character variables instead (example below)?

 

num rater1 rater2 rater3 rater4 rater5 rater6  Flag2
Pt1         a         a        a          a        a      a       0

Pt2         b         a        a          a        a      a       1

Pt3         a         b        c          c        b      a       0

Pt4         c         a         c          c        c      c       1

Ksharp
Super User
data have;
input (num rater1 rater2 rater3 rater4 rater5 rater6) ($) ;
cards;
Pt1         a         a        a          a        a      a       
Pt2         b         a        a          a        a      a       
Pt3         a         b        c          c        b      a       
Pt4         c         a         c          c        c      c  
;
run;
data want;
if _n_=1 then do;
 length k $ 80;
 declare hash h();
 h.definekey('k');
 h.definedone();
end;
set have;
array x{*} $ rater1-rater6;
do i=1 to dim(x);
 if not missing(x{i}) then do;k=x{i}; h.ref();end;
end;
flag=h.num_items=2;
h.clear();
drop i k;
run;

proc print;run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 630 views
  • 2 likes
  • 3 in conversation