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,
Thanks but I think I figured it out with a case statement
case
when not missing(parentcompany) then parentcompany
else company
end
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.
Thanks but I think I figured it out with a case statement
case
when not missing(parentcompany) then parentcompany
else company
end
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!
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.