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
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!
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.
Ready to level-up your skills? Choose your own adventure.