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

 

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
  • 2 replies
  • 516 views
  • 0 likes
  • 2 in conversation