BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Josh12
Calcite | Level 5
Please, I need your help to solve a problem I had after I concatenated "Lastname, first name, and middle name. I want the characters to look like this, e.g., Johnson, Smart B. However, I was successful doing that, but I have two different people in different departments with the names (e.g., Smith, Johnson L maybe in English dept and another person bearing the same Smith, Johnson L in French Dept). Please, how can I solve this problem before joining the data set? How do I remove the initial from one of the names to make the concatenation or names unique by person?

Show less

 
1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
mkeintz
PROC Star

You need a way to determine whether a tentative new name has already been established for another person.

 

Show us the code (as a complete data step, or complete proc sql)  that you are currently using - USING THE mkeintz_1-1648610790076.png 

OR

 mkeintz_2-1648610870933.png 

ICONS.  That is essential to developing code to detect duplicates.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Josh12
Calcite | Level 5

data emp1; set emp;

length name $70.;

middle_name2=substr(middle_name,1,1);

name_MI=trim(last_name)||", "||trim(first_name)||" "||trim(middle_name2);

first_name_i=scan(first_name,1);

name=trim(last_name)||", "||trim(first_name_i);

run;

 

I have a base data that was set up already as (Lastname, Firstname middle initial like Smart, Johnson L). 

Tom
Super User Tom
Super User

Don't bother making the NAME unique.  Create an ID variable that is unique.

Something like:

data want;
  set have;
  id+1;
  new_name = catx(', ',last_name,catx(' ',first_name,middle_initial));
run;

Then use their ID when combining the names with other data you have about them.

Astounding
PROC Star
For the unique identifier, don't use NAME. use NAME plus DEPT.
ballardw
Super User
And depending on your data you may need to actually investigate that the name is not actually the same person. People change positions within organizations, sometimes frequently. If you data does not represent a single point in time, i.e. only 15 Mar 2022, but some interval then that person might occur as part of two different organizations.
Which is why a very large number of organizations use an Employee, or from your context, Student identifier instead of names.
mkeintz
PROC Star

 

@Astounding's suggestion is good for the current situation, assuming no department currently has two people with the same name.

 

But people change departments - and much less frequently they change names.  Either the identifier will remain fixed, but lose informational value (so why use name & dept to begin with?)   -  or it will be modified to follow the employee's changes, requiring a table of links between old and new identifiers.

 

There will be blood.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

@mkeintz wrote:

 

@Astounding's suggestion is good for the current situation, assuming no department currently has two people with the same name.

 

But people change departments - and much less frequently they change names.  Either the identifier will remain fixed, but lose informational value (so why use name & dept to begin with?)   -  or it will be modified to follow the employee's changes, requiring a table of links between old and new identifiers.

 

There will be blood.


Sounds like you may have bitten by the same things that I have. Including the "new database implementation will use new identifiers" headache.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 7 replies
  • 752 views
  • 0 likes
  • 5 in conversation