Solved
Contributor
Posts: 65

# Getting values in one column

Hi All,

I know this is a very stupid question to ask, but I am bit confused with the following:

How can I get the First Name and Middle Name in the same column and Last name in a different column?

As I don't have double space before the last name so I can't use '&' in my INPUT statement.

Data Sample;

Input First_name \$ Last_Name;

Cards;

John Beth Goodrich

;

Run;

Result:

First_Name               Last_Name

Winston Anthony      Samuel

John Beth                 Goodrich

Accepted Solutions
Solution
‎09-27-2011 03:41 PM
PROC Star
Posts: 8,163

## Getting values in one column

I'm sure there are a number of ways to do it.  If you ALWAYS have first and middle names then you could use something like:

Data Sample (drop=Middle_name);

length First_name \$30.;

informat First_name Middle_name Last_Name \$15.;

input First_name Middle_name Last_Name;

First_name=catx(' ',First_name,Middle_name);

cards;

John Beth Goodrich

;

All Replies
Solution
‎09-27-2011 03:41 PM
PROC Star
Posts: 8,163

## Getting values in one column

I'm sure there are a number of ways to do it.  If you ALWAYS have first and middle names then you could use something like:

Data Sample (drop=Middle_name);

length First_name \$30.;

informat First_name Middle_name Last_Name \$15.;

input First_name Middle_name Last_Name;

First_name=catx(' ',First_name,Middle_name);

cards;

John Beth Goodrich

;

Super User
Posts: 8,069

## Getting values in one column

This is actually a difficult problem to handle properly as some last names include spaces.

data sample;

input @ ;

length first_name \$50 last_name \$50 ;

last_name = scan(_infile_,-1,' ');

first_name = substr(_infile_,1,length(_infile_)-length(last_name));

cards;

John Beth Goodrich

;

Run;

Valued Guide
Posts: 2,191

## Getting values in one column

is there always just one middle name?

how often might a "last name" be more than one word (not counting double-barrelled surnames separated with a ( - ) hyphen )?

I have two middle names. Should both follow my first name?

Contributor
Posts: 65

## Getting values in one column

@Art and @Tom - Thanks for sharing the knowledge.

@Peter, Well it depends on the business rules and requirements. I was writing some code and came up with this and was not able to think clearly on the solution. So that's the reason I came up with this question.

🔒 This topic is solved and locked.