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

Hello,

I have a csv file that I'm working on that list members to a club.  The data is very bad and I'm trying to clean it up.  The first issue is that they put multiple people to one row using commas to seperate.  So the fname field could have 1 or many commas.  I want to take every field and leave it the same except for FName.  For example

FName                           LName       Address        

Bob, Joe, William, Dave  Jones         1234 Test St

There are many more variables but this is how I need the data to render

FName                           LName       Address        

Bob                               Jones         1234 Test St

Joe                               Jones         1234 Test St

William                         Jones          1234 Test St
Dave                            Jones         1234 Test St

Thank you for any help you can give me.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

data have;

  informat FName LName Address $50.;

  input (FName  LName       Address) (&);

  cards;       

Bob, Joe, William, Dave  Jones         1234 Test St

;

data want (drop=_:);

  length FName $50;

  set have (rename=FName=_FName);

  _i=1;

  do while (scan(_FName,_i,',') ne '');

    FName=scan(_FName,_i,',');

    output;

    _i+1;

  end;

run;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

data have;

  informat FName LName Address $50.;

  input (FName  LName       Address) (&);

  cards;       

Bob, Joe, William, Dave  Jones         1234 Test St

;

data want (drop=_:);

  length FName $50;

  set have (rename=FName=_FName);

  _i=1;

  do while (scan(_FName,_i,',') ne '');

    FName=scan(_FName,_i,',');

    output;

    _i+1;

  end;

run;

jerry898969
Pyrite | Level 9

Hi Arthur,


Thank you so much.  That worked perfectly.

You have been a great help to me and I truly appreciate it.

Thank you,

Jerry

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1136 views
  • 0 likes
  • 2 in conversation