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

I have following dataset. i want to create another flag based on status value by type.

if for a type status=True then Flag should be "true" for all type & if a type contains both true & false value under status then let it be "Partial" and if for a type status=False then Flag should be "Flase" for all type.

 

 

data one;

input type $  Status $12.;

datalines;
A true

A false B false C true C true C true E false E false E false
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use a double do loop:

data one;
input type $ Status :$12.;
datalines;
A true
A false
A false
C true
C true
C true
E false
E false
E false
;

data want;
do until(last.type);
  set one;
  by type;
  f = max(f,ifn(status='false',1,0));
  t = max(t,ifn(status='true',1,0));
end;
if f and t
then flag = 'Partial';
else if f
then flag = 'False';
else if t
then flag = 'True';
else flag = 'Undef';
do until (last.type);
  set one;
  by type;
  output;
end;
drop t f;
run;

proc print data=want noobs;
run;

Result:

type    Status    flag

 A      true      Partial
 A      false     Partial
 A      false     Partial
 C      true      True   
 C      true      True   
 C      true      True   
 E      false     False  
 E      false     False  
 E      false     False  

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Use a double do loop:

data one;
input type $ Status :$12.;
datalines;
A true
A false
A false
C true
C true
C true
E false
E false
E false
;

data want;
do until(last.type);
  set one;
  by type;
  f = max(f,ifn(status='false',1,0));
  t = max(t,ifn(status='true',1,0));
end;
if f and t
then flag = 'Partial';
else if f
then flag = 'False';
else if t
then flag = 'True';
else flag = 'Undef';
do until (last.type);
  set one;
  by type;
  output;
end;
drop t f;
run;

proc print data=want noobs;
run;

Result:

type    Status    flag

 A      true      Partial
 A      false     Partial
 A      false     Partial
 C      true      True   
 C      true      True   
 C      true      True   
 E      false     False  
 E      false     False  
 E      false     False  
ASHISH2525
Quartz | Level 8

Thank you Kurt !

 

It worked. 

 

 

 

Regards,

Ashish

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 947 views
  • 2 likes
  • 2 in conversation