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;

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