Hello,
Relatively new to SAS Enterprise guide. I am trying to add two columns together into one but would like to add the values if there are no missing values. When there are missing values I would like a 0 in its place.
Example:
This is what I could like:
Column 1 Column 2 New Column
4 6 10
0 0 0
1 0 1
0 1 1
I have tried coalesce(t1.Column 1,t1.Column 2) but this does not add the values.
Thank you in advance!
You need to have two calculations, a SUM to do the addition and a COALESCE to replace with 0 if missing.
coalesce(sum(t1.Column 1,t1.Column 2), 0)
@andimo89 wrote:
Hello,
Relatively new to SAS Enterprise guide. I am trying to add two columns together into one but would like to add the values if there are no missing values. When there are missing values I would like a 0 in its place.
Example:
This is what I could like:
Column 1 Column 2 New Column
4 6 10
0 0 0
1 0 1
0 1 1
I have tried coalesce(t1.Column 1,t1.Column 2) but this does not add the values.
Thank you in advance!
You are looking for the SUM function. It ignores missings.
You need to have two calculations, a SUM to do the addition and a COALESCE to replace with 0 if missing.
coalesce(sum(t1.Column 1,t1.Column 2), 0)
@andimo89 wrote:
Hello,
Relatively new to SAS Enterprise guide. I am trying to add two columns together into one but would like to add the values if there are no missing values. When there are missing values I would like a 0 in its place.
Example:
This is what I could like:
Column 1 Column 2 New Column
4 6 10
0 0 0
1 0 1
0 1 1
I have tried coalesce(t1.Column 1,t1.Column 2) but this does not add the values.
Thank you in advance!
Thank you so much!!! This worked perfectly! I appreciate it. 😊
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.