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

I'm normally a point and click EG user, so I'm having trouble writing the code to produce the following results by writing code. 

 

One issue I have is each ID_NUM can have an unknown count of CSC's associated to it. 

 

work.DO
OfficeID_NUMDate of BirthBOSS_IDCSC
0602336739/15/201060118175X
0602336739/15/201060118152X
0602336739/16/201060119280X
0605491535/18/199960321921X
0605491535/18/199960321929X

 

to...

 

work.DO_NEW
OfficeID_NUMDate of BirthBOSS_IDCSC_NEW
0602336739/15/201060118175X, 152X, 280X
0605491535/18/199960321921X, 929X

 

Thanks for any help provided!

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There are a lot of posts on this topic on here already, please check search bar before posting.  Retain and by:

data want (drop=csc);
  set have;
  by office id_num;
  length csc_new $200;
  retain csc_new;
  csc_new=ifc(first.id_num,csc,catx(',',csc_new,csc));
  if last.id_num then output;
run;

Do note, assumes sorted.  Also your test data has 2 boss_id's in one id_num, could be an issue?

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There are a lot of posts on this topic on here already, please check search bar before posting.  Retain and by:

data want (drop=csc);
  set have;
  by office id_num;
  length csc_new $200;
  retain csc_new;
  csc_new=ifc(first.id_num,csc,catx(',',csc_new,csc));
  if last.id_num then output;
run;

Do note, assumes sorted.  Also your test data has 2 boss_id's in one id_num, could be an issue?

ballardw
Super User

How is the variable CSC_NEW going to be used?

 

With the value of CSC ever be duplicated within any ID_NUM group? If so what would the final result look like?

 

What is the explicit rule that BOSS_id 60119 is grouped with 60118? Is this grouping strictly on ID_num and the date of birth and boss_id are taken from the first row of ID_NUM?

accesnh
Fluorite | Level 6

the 60119 and 60118 was a typo.  The above mentioned code worked perfectly.  No, the CSC will never be a duplicate because I'm making that a distinct field in a prior query.  Thanks!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Do note, @ballardw makes a very good point.  If that concatenated variable is not being used for just an output file (i.e. just printed), then it is far better to keep data items in their own individual variables for processing.  It is not good practice to program with variables containing multiple data items.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 24927 views
  • 2 likes
  • 3 in conversation