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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 609 views
  • 0 likes
  • 2 in conversation