Help using Base SAS procedures

count

Reply
Occasional Contributor
Posts: 14

count

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

Occasional Contributor
Posts: 10

Re: count

Posted in reply to sasemp999

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

Respected Advisor
Posts: 3,156

Re: count

Posted in reply to sasemp999

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=_Smiley Happy;

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 _Smiley Happy;

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;

Ask a Question
Discussion stats
  • 2 replies
  • 169 views
  • 0 likes
  • 3 in conversation