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

Table data_1
CIF ACNO AMT
123 14 100
123 15 200
123 16 200
159 17 100
159 18 200
159 19 200
159 20 200
159 30 200

 

Table data_2
CIF AMT
123 -400
159 -1500

Please guide for SAS procedure for the following: DATA_1.AMT should be mapped BY CIF and adjusted by DATA_2.AMT and the both table updated with NEW_AMT as under:

 Table data_1
CIF ACNO AMT  NEW_AMT
123 14 100  0
123 15 200  0
123 16 200  100
159 17 100  0
159 18 200  0
159 19 200  0
159 20 200  0
159 30 200  0

 

Table data_2

CIF AMT NEW_AMT
123 -400 0
159 -1500 -600

 

Many thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep using the code window (its the {i} above post area).

As such it seems that you want to merge the big number from table two onto the last record of the first table, and take that number off.  If so:

data want;
  merge data_1 data_2 (rename=(amt=_amt));
  by cif;
run;

data want;
  set want;
  by cif;
  retain running;
  running=ifn(first.cif,amt,sum(running,amt));
  if last.cif then new_amt=running-_amt;
run;

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep using the code window (its the {i} above post area).

As such it seems that you want to merge the big number from table two onto the last record of the first table, and take that number off.  If so:

data want;
  merge data_1 data_2 (rename=(amt=_amt));
  by cif;
run;

data want;
  set want;
  by cif;
  retain running;
  running=ifn(first.cif,amt,sum(running,amt));
  if last.cif then new_amt=running-_amt;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 532 views
  • 1 like
  • 2 in conversation