BookmarkSubscribeRSS Feed
marleeakerson
Calcite | Level 5

Hello, 

 

I have a variable with first and last names and I am trying to separate them into two separate variables. See the sample data below: 

Name 

Smith Joe

Reynolds Jack 

Anderson Amy 

 

But I want the data to read: 

Last Name                          First Name 

Smith                                        Joe 

Reynolds                                   Jack 

Anderson                                   Amy

 

Does anyone have any advice for me? Thank you!

1 REPLY 1
PaigeMiller
Diamond | Level 26

The SCAN function will do this for the simple cases you have shown.

 

firstname=scan(name,2);
lastname=scan(name,1);

But things get very confusing if the last name has a space in it, or if the first name has a space in it. So, the above really doesn't constitute a real-word solution. You need to define the problem much more precisely.

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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