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?
Reframing your logic:
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 0Pt2 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?
Reframing your logic:
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 0Pt2 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?
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
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;
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!
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.