BookmarkSubscribeRSS Feed
WorkUser
Obsidian | Level 7

I have the following data set:

ID

Co Name

12345

ABC COMPANY

12345

Abc company

 

Is it possible to create a new computed column called “New Name” in SAS EG query builder to take one of the “Co Name” when the ID matches? also there are data fields that 'ID' is null but has a 'Co Name'. I would like to leave those data field as is. 

Thanks

4 REPLIES 4
ballardw
Super User

Matches what? As in: "Is it possible to create a new computed column called “New Name” in SAS EG query builder to take one of the “Co Name” when the ID matches?"  And since you are showing multiple values of  "Co Name" for the same Id, which specific "Co name" would be the result?

 

Your comment about "there are data fields that 'ID' is null but has a 'Co Name'. I would like to leave those data field as is. " makes me ask for a bit more of an example, what your matching and where it resides and what the result of the process given the shown example data should be.

 

 

 

 

WorkUser
Obsidian | Level 7

hope this helps to clarify.

Original data:

ID

Co Name

12345

ABC COMPANY

12345

Abc company

 

Xyz Company

 

XYZ COMPANY

67890

asd Co

 

Output data:

ID

NEW Co Name

12345

ABC COMPANY

 

Xyz Company

 

XYZ COMPANY

67890

asd Co

 

Patrick
Opal | Level 21

Below the SQL you need to create via point&click

proc sql;
  select distinct
    id, 
    case 
      when not missing(id) then upcase(co_name)
      else co_name
      end
      as new_name
  from have
  ;
quit;
WorkUser
Obsidian | Level 7

Additional clarification. I would like the “NEW Co Name” column to output the “Co Name” with the most occurrences.

 

Original data:

ID

Co Name

12345

ABC COMPANY

12345

ABC COMPANY

12345

ABC COMPANY

12345

Abc company

12345

Abc company

 

Xyz Company

 

XYZ COMPANY

67890

asd Co

 

Output data:

ID

NEW Co Name

12345

ABC COMPANY

 

Xyz Company

 

XYZ COMPANY

67890

asd Co

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 445 views
  • 0 likes
  • 3 in conversation