BookmarkSubscribeRSS Feed
Lapis Lazuli | Level 10

Hi Guys,

name='George W. Bush'

required output:

Fname                      lname

George W.                Bush

Barite | Level 11

Hi @Anandkvn; have a look here: Separate Full Name to FirstName and LastName - SAS Support Communities

(And next time please look for existing solutions before asking already answered questions.)



Please keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at
Quartz | Level 8
data output;
   set YourDataset; /* Replace "YourDataset" with the name of your actual dataset */

   Fname = scan(full_name, 1); /* Assuming the full name is stored in a variable called "full_name" */
   Lname = scan(full_name, -1); /* Extracts the last word in the full name */

   /* Output the formatted names */
   put "Fname: " Fname;
   put "Lname: " Lname;

In this code, you need to replace "YourDataset" with the actual name of your dataset containing the full names. The SCAN function is used to extract the first name (Fname) and last name (Lname) from the variable full_name. The -1 as the second argument of SCAN tells SAS to extract the last word in the string. Finally, the put statements are used to display the formatted output in the SAS log.

Make sure to adjust the code according to your specific dataset and variable names.

Super User
data have;
name='George W. Bush';

call scan(name,-1,p,l,' ');

proc print;run;
Super User

Now, what do you expect for a "first" and "last" name from these names


Sun Flower Moon Child

John Richard II Van Opdorp

Maria Garcia Y Mendoza

Smith, John David Junior

Junior Childs Junior


There are rules for parsing names that are cultural and almost any simple one or two line programming solution won't "work" for all of them and may not work for large numbers.


If the question is "what are the first two words out of this list of 3 words" that is one thing.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 5 in conversation