my input dataset like
patientno count_bp count_heartattack count_death
1 1 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 1 0 0
2 1 1 0
2 1 1 1
3 0 0 0
3 0 1 0
i want to get output like
if the patient is suffering from bp ,1 times,2 times,3 times we have to get in output min(bp attcked)-1
if the patient is not suffering from bp-in output we have to get-0
if the patient is suffering from heartattack ,1 times,2 times,3 times we have to get in output min(heart attcked)-1
if the patient is not suffering from heart attack-in output we have to get-0
if the patient is died-count_death=1 otherwise count_Death=0
for the above example we have to get output like
patientno count_bp count_heartattack count_death
1 1 1 1
2 1 1 0
3 1 1 0
Sure your output dataset is correct and you need min and not max ?
Try this:
proc sort data=test; by patientno; run;
data test1 (rename=(f_bp=count_bp f_heartattack=count_heartattack f_death=count_death )) ;
retain f_bp f_heartattack f_death;
set test;
by patientno;
if first.patientno then do;
f_bp=0;
f_heartattack=0;
f_death=0;
end;
if count_bp>f_bp then f_bp=count_bp;
if count_heartattack>f_heartattack then f_heartattack=count_heartattack;
if count_death=1 then f_death=1;
if last.patientno;
drop count_bp count_heartattack count_death;
run;
Best regards,
Gerd
Another approach:
data have;
input
patientno$ count_bp count_heartattack count_death;
cards;
1 1 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 1 0 0
2 1 1 0
2 1 1 1
3 0 0 0
3 0 1 0
;
data want (drop=_:);
do until (last.patientno);
set have;
by patientno notsorted;
_count_bp+count_bp;
_count_heartattack+ count_heartattack;
_count_death+count_death;
end;
count_bp=(_count_bp>0);
count_heartattack=(_count_heartattack>0);
count_death=(_count_death>0);
output;
call missing (of _:);
run;
proc print;run;
Haikuo
Update: SQL makes more sense in this case:
proc sql;
create table want as
select patientno, sum(count_bp)>0 as count_bp, sum(count_heartattack)>0 as count_heartattack
, sum(count_death)>0 as count_death
from have
group by patientno;
quit;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.