BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WorkUser
Obsidian | Level 7

Can I do a computed column in SAS EG query builder to create a new column that merges two different columns into one. Below is an example of what I’m talking about:

 

Item Number

Company

Parent Company

1234

ABC LLC

ABC Inc

5678

123 LLC

123 Inc

9123

 

XYZ Inc

8765

QRT LLC

 

 

Create a new column to show:

Item Number

New Column

1234

ABC Inc

5678

123 Inc

9123

XYZ Inc

8765

QRT LLC

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
WorkUser
Obsidian | Level 7

Thanks but I think I figured it out with a case statement

 

case

when not missing(parentcompany) then parentcompany
else company

end

 

View solution in original post

2 REPLIES 2
ballardw
Super User

Don't know how query builder might use the COALESCEC function but that appears to be what you want. Look for how to build an expression.

The generated code would look something like:

Proc sql;
   create table new as
   select itemnumber, coalescec(company,parentcompany) as newcolumn
   from have;
run;

The Coalescec function for character values, and Coalesce for numeric, returns the first value encountered in the list of values provided in the function call in order from left to right. So when Company is populated that is the result, when missing then Parentcompany is the result. If both are missing the result will be missing.

WorkUser
Obsidian | Level 7

Thanks but I think I figured it out with a case statement

 

case

when not missing(parentcompany) then parentcompany
else company

end

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1038 views
  • 0 likes
  • 2 in conversation