- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have data set like below...
data stansys;
infile datalines;
input id name&$24. sal;
datalines;
101 Richard Rose 5000
102 Yao Chen Hoo 6000
103 Asha Garg Bette Long 7000
104 Jason Blue 9000
105 Susan Robert Stewart 8000
;
run;
Through this dataset i want output dataset with seperating as First name and Middle name and last name...
So please give a programme for this !!!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Mohan_Reddy wrote:
Here First name="Richard" and Last name="Rose" if another records have two separate names in string you will take first name,Middle name1,Middle name2,Last name......No issues
And how many middle names do you expect in your data?
I also like to point you to https://communities.sas.com/t5/New-SAS-User/How-to-take-patient-name-and-split-into-first-name-and-l..., especially the message from PaigeMiller, showing that extracting name-parts is not that easy.
Try:
data want;
set stansys;
length first middle1 middle2 last $ 40;
array parts[*] first middle1 middle2 last;
do i = 1 to countw(name);
if i = countw(name) and i < dim(parts) then do;
parts[dim(parts)] = scan(name, i);
end;
else do;
parts[i] = scan(name, i);
end;
end;
drop i;
run;
If you want all middle-names in a single variable, i would use a regular expression.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In a name like "Asha Garg Bette Long", what do you want the first, middle and last name to be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"Asha Garg Bette Long" through this You will take Middle name1="Garg" and Middle name2="Bette Like no issues.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Taking the first row of your data, both "Richard" and "Rose" could be first names. So please define which words are first name, middle name and last name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here First name="Richard" and Last name="Rose"
if another records have two separate names in string you will take first name,Middle name1,Middle name2,Last name......No issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Mohan_Reddy wrote:
Here First name="Richard" and Last name="Rose" if another records have two separate names in string you will take first name,Middle name1,Middle name2,Last name......No issues
And how many middle names do you expect in your data?
I also like to point you to https://communities.sas.com/t5/New-SAS-User/How-to-take-patient-name-and-split-into-first-name-and-l..., especially the message from PaigeMiller, showing that extracting name-parts is not that easy.
Try:
data want;
set stansys;
length first middle1 middle2 last $ 40;
array parts[*] first middle1 middle2 last;
do i = 1 to countw(name);
if i = countw(name) and i < dim(parts) then do;
parts[dim(parts)] = scan(name, i);
end;
else do;
parts[i] = scan(name, i);
end;
end;
drop i;
run;
If you want all middle-names in a single variable, i would use a regular expression.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In 2 and 3 and 5 Rows only you will Take First Name,Middle Name1,Middle Name2,Last Name like that i want output.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Mohan_Reddy wrote:
In First row First Name ="Richard" and Last Name="Rose"...
In 2 and 3 and 5 Rows only you will Take First Name,Middle Name1,Middle Name2,Last Name like that i want output.....
You may also have to consider names such as "de la Cruz" or "van Dyke" which are not unlikely last names if you have enough.
Also do you have any titles such as Dr. Ms. Esq. in the data?
Of things like Junior, "the third", II and similar ilk?
If at all practical I would go the source and see if they can create a separate clearly delimited file with each of first., last and middle names.