🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-26-2018 05:09 PM
(6580 views)
Need advise:
I have data as this:
Month | ID | Code | Count |
201806 | 30712566 | XB3 | 2 |
201806 | 30712566 | Z99 | 1 |
I need to have result as this:
Month | ID | Code | Count |
201806 | 30712566 | XB3,Z99 | 3 |
Please advise and help
Thank you
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
infile cards truncover;
input Month ID Code $ Count;
cards;
201806 30712566 XB3 2
201806 30712566 Z99 1
;
data want;
set have;
by month id;
length _code $10;
retain _code;
if first.id then do; _code=code;_count=count;end;
else do; _code=catx(',',_code,code);_count+count;end;
if last.id;
run;
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
infile cards truncover;
input Month ID Code $ Count;
cards;
201806 30712566 XB3 2
201806 30712566 Z99 1
;
data want;
set have;
by month id;
length _code $10;
retain _code;
if first.id then do; _code=code;_count=count;end;
else do; _code=catx(',',_code,code);_count+count;end;
if last.id;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Make sure the length of the _CODE variable is long enough to hold the maximum number of codes you expect and include extra characters for the commas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I agree