BookmarkSubscribeRSS Feed
marleeakerson
Calcite | Level 5

Hello, 

 

I currently have a variable that contains a last name and first name, and I want to split it up into two separate variables, one for the last name and one for the first name. 

 

For example, I want the data to go from: 

Name

Smith Julia

Johnson Mark 

Reynolds Steve

 

to this: 

Last Name      First Name 

Smith                  Julia 

Johnson              Mark 

Reynolds             Steve 

 

Does anyone have any advice? 

 

Thanks!

1 REPLY 1
Reeza
Super User

What would you do for a name like "Eddie Van Halen"?

 

Otherwise, in a simplistic situation illustrated, SCAN() works.

 

data want;
set have;

firstName = scan(name, 2);
lastName = scan(name, 1);

run;

@marleeakerson wrote:

Hello, 

 

I currently have a variable that contains a last name and first name, and I want to split it up into two separate variables, one for the last name and one for the first name. 

 

For example, I want the data to go from: 

Name

Smith Julia

Johnson Mark 

Reynolds Steve

 

to this: 

Last Name      First Name 

Smith                  Julia 

Johnson              Mark 

Reynolds             Steve 

 

Does anyone have any advice? 

 

Thanks!


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 769 views
  • 2 likes
  • 2 in conversation