SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

Need advise:

 

I have data as this:

Month IDCode Count
20180630712566XB32
20180630712566Z99

1

 

I need to have result as this:

 

Month IDCode Count
20180630712566XB3,Z993

 

Please advise and help

 

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;
ballardw
Super User

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.

novinosrin
Tourmaline | Level 20

I agree

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 6581 views
  • 1 like
  • 3 in conversation