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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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