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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 681 views
  • 0 likes
  • 2 in conversation