Hello,
I want to add/sum up and merge two columns that are in 2 different tables. What is the best logic/method that would be used for this type of situation?
For example, I want to join Table A & B and merge the 'Amount' column and sum up the numbers.
Table A
Security Group | METHOD | Amount |
Unprotected | % | 10 |
Protected | Flat | 10 |
Protected | Flat | 10 |
Protected | Flat | 10 |
Protected | Flat | 10 |
Protected | Flat | 15 |
Unprotected | % | 15 |
Protected | Flat | 15 |
Protected | Flat | 20 |
Protected | % | 50 |
Protected | % | 100 |
Table B
Active vs. Expired | Security Group | METHOD | Amount |
Active | Unprotected | % | 10 |
Active | Protected | Flat | 10 |
Expired | Protected | Flat | 10 |
Expired | Protected | Flat | 10 |
Expired | Protected | Flat | 10 |
Active | Protected | Flat | 15 |
Active | Unprotected | % | 15 |
Expired | Protected | Flat | 15 |
Active | Protected | Flat | 20 |
Expired | Protected | % | 50 |
Active | Protected | % | 100 |
The desired result for Table C:
Active vs. Expired | Security Group | METHOD | Amount |
Active | Unprotected | % | 20 |
Active | Protected | Flat | 20 |
Expired | Protected | Flat | 20 |
Expired | Protected | Flat | 20 |
Expired | Protected | Flat | 20 |
Active | Protected | Flat | 30 |
Active | Unprotected | % | 30 |
Expired | Protected | Flat | 30 |
Active | Protected | Flat | 40 |
Expired | Protected | % | 100 |
Active | Protected | % | 200 |
If you are absolutely certain that the tables match, line per line, simply do this:
data c;
set a;
set b(rename=amount=extra);
amount = amount + extra;
drop extra;
run;
If you are absolutely certain that the tables match, line per line, simply do this:
data c;
set a;
set b(rename=amount=extra);
amount = amount + extra;
drop extra;
run;
THANK YOU!!! 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.