BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sufiya
Quartz | Level 8

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 GroupMETHODAmount
   
Unprotected%10
ProtectedFlat10
ProtectedFlat10
ProtectedFlat10
ProtectedFlat10
ProtectedFlat15
Unprotected%15
ProtectedFlat15
ProtectedFlat20
Protected%50
Protected%100

 

 

Table B

Active vs. ExpiredSecurity GroupMETHODAmount
    
ActiveUnprotected%10
ActiveProtectedFlat10
ExpiredProtectedFlat10
ExpiredProtectedFlat10
ExpiredProtectedFlat10
ActiveProtectedFlat15
ActiveUnprotected%15
ExpiredProtectedFlat15
ActiveProtectedFlat20
ExpiredProtected%50
ActiveProtected%100

 

The desired result for  Table C:

Active vs. ExpiredSecurity GroupMETHODAmount
    
ActiveUnprotected%20
ActiveProtectedFlat20
ExpiredProtectedFlat20
ExpiredProtectedFlat20
ExpiredProtectedFlat20
ActiveProtectedFlat30
ActiveUnprotected%30
ExpiredProtectedFlat30
ActiveProtectedFlat40
ExpiredProtected%100
ActiveProtected%200
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20
You can't do this using proc sql as it doesn't necessarily read tables sequentially. You need a data step here.
PGStats
Opal | Level 21

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;
PG
sufiya
Quartz | Level 8

THANK YOU!!! 🙂

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4039 views
  • 1 like
  • 3 in conversation