/*
OK. Test the following code.
If there was something wrong,post an example.
*/
data have;
Input Id visitn testcd $ result baseresult basefl $ pstbsfl $;
datalines;
1 1 ALT 12 3 . Y
1 2 AST 3 1 . Y
2 1 AST 3 1 Y .
2 2 AST 2 1 . Y
;
run;
proc sql;
create table want as
select *,
case when max(pstbsfl='Y' and testcd='ALT') and
max(pstbsfl='Y' and testcd='ALT' and result>=4*baseresult) then 'Y'
when max(pstbsfl='Y' and testcd='ALT') and
max(pstbsfl='Y' and testcd='ALT' and result>=4*baseresult)=0 then 'N'
when max(pstbsfl='Y' and testcd='ALT')=0 then ' '
else 'X' end as critfl
from have
group by id;
quit;
EDITED.
... View more