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;
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
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
Thank you Kurt !
It worked.
Regards,
Ashish
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: