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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.