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

Hi all, 

 

I'm trying to create a new table that does 2 things with the dataset. 

  1. If the account reaches a cumulative minimum deposit of $500 and
  2. In which day the account reached a cumulative minimum deposit of $500.

I'm more comfortable with proc sql but can use data step. 

AccountDeposit_DtAmount
A12345Day1100
A12345Day5200
A12345Day10300
B12346Day150
B12346Day6150
B12346Day16250
C12347Day2500
C12347Day5100
C12347Day1950
D12348Day4200
D12348Day28100

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Account $ Deposit_Dt $ Amount;
datalines;
A12345 Day1  100
A12345 Day5  200
A12345 Day10 300
B12346 Day1  50 
B12346 Day6  150
B12346 Day16 250
C12347 Day2  500
C12347 Day5  100
C12347 Day19 50 
D12348 Day4  200
D12348 Day28 100
;

data want(drop = cum r);
   set have;
   by Account;
   if first.Account then do;
      cum = Amount; r = 0;
   end;
   else cum + Amount;
   if cum ge 500 and r = 0 then do;
      flag = 1; r = 1;
   end;
   retain r;
run;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Account $ Deposit_Dt $ Amount;
datalines;
A12345 Day1  100
A12345 Day5  200
A12345 Day10 300
B12346 Day1  50 
B12346 Day6  150
B12346 Day16 250
C12347 Day2  500
C12347 Day5  100
C12347 Day19 50 
D12348 Day4  200
D12348 Day28 100
;

data want(drop = cum r);
   set have;
   by Account;
   if first.Account then do;
      cum = Amount; r = 0;
   end;
   else cum + Amount;
   if cum ge 500 and r = 0 then do;
      flag = 1; r = 1;
   end;
   retain r;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 571 views
  • 0 likes
  • 2 in conversation