BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASPhile
Quartz | Level 8

There is a table with below data structrue:


id    aesoc     aeterm            Count
1     Heart    Atrial fibrillation   25
1    Heart   Cardiac arrest       27

2    Ear       Deafness             10

2    Ear       Ear Pain                  5

Need help in adding the value of aesoc to aterm so all the records that belong to heart will be under under one column.

id   aeterm                     Count          rec_add
1      Heart                     42                     Y
1    Atrial fibrillation       25
1    Cardiac arrest        27

2    Ear                         15                      Y

2    Deafness                10

3   Ear Pain                     5

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

There you go 

 

data have;
input id aesoc $ aeterm :$30. Count;
infile datalines dlm=',';
datalines;
1,Heart,Atrial fibrillation,25
1,Heart,Cardiac arrest,27
2,Ear,Deafness,10
2,Ear,Ear Pain,5
;

data want(drop=sum);

   do until (last.id);
      set have;
      by id;
      sum=sum(sum, count);
   end;

   Count=sum;aeterm=aesoc;rec_add='Y';
   output;
   rec_add='';

   do until (last.id);
      set have;
      by id;
      output;
   end;

run;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

There you go 

 

data have;
input id aesoc $ aeterm :$30. Count;
infile datalines dlm=',';
datalines;
1,Heart,Atrial fibrillation,25
1,Heart,Cardiac arrest,27
2,Ear,Deafness,10
2,Ear,Ear Pain,5
;

data want(drop=sum);

   do until (last.id);
      set have;
      by id;
      sum=sum(sum, count);
   end;

   Count=sum;aeterm=aesoc;rec_add='Y';
   output;
   rec_add='';

   do until (last.id);
      set have;
      by id;
      output;
   end;

run;