BookmarkSubscribeRSS Feed
sasemp999
Calcite | Level 5

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

2 REPLIES 2
Gerd47
Calcite | Level 5

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

Haikuo
Onyx | Level 15

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;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 699 views
  • 0 likes
  • 3 in conversation