BookmarkSubscribeRSS Feed
franph
Calcite | Level 5

Hi

I would like to code this..

if trandate in current ob = trandate in next ob then delete dailybal, accringbal & aggregatebal  from current ob

sample input dataset....

trandate          amount     dailybal     accruingbal     aggregatebal    

28/01/2015                                        3451.76            3451.76

29/01/2015                                        3451.76            6903.52  

30/01/2015     -50.00       -50.00        3401.76            10305.28       .       

31/01/2015                                         3401.76            13707.04                      

01/02/2015      56.60       223.59         3625.35           117332.39

01/02/2015      166.99     223.59       3625.35           117332.39

02/02/2015                                         3625.35          20957.74

desired result

trandate          amount     dailybal     accruingbal     aggregatebal    

28/01/2015                                        3451.76            3451.76

29/01/2015                                        3451.76            6903.52  

30/01/2015     -50.00       -50.00        3401.76            10305.28       .       

31/01/2015                                         3401.76            13707.04                      

01/02/2015      56.60      

01/02/2015      166.99     223.59       3625.35           117332.39

thanks for your help 🙂

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try

data want;

set have;

by  trandate;

retain seq;

if first.trandate then seq=1;

else seq+1;

run;

data want2;

merge want(in=a) want(in=b keep=seq rename=(seq=flag2) firstobs=2);

if flag2>1 then call missing (dailybal , accruingbal, aggregatebal);

run;

Thanks,

Jag

Thanks,
Jag
KachiM
Rhodochrosite | Level 12

Try this too.

data have;

input trandate ddmmyy10. amount dailybal accruingbal aggregatebal;   

datalines;

28/01/2015        .     .         .     3451.76     3451.76

29/01/2015        .     .         .     3451.76     6903.52

30/01/2015     -50.00 -50.00   3401.76  10305.28       .  

31/01/2015        .      .       .       3401.76   13707.04

01/02/2015      56.60  223.59  3625.35 117332.39      .

01/02/2015     166.99  223.59  3625.35 117332.39      .

02/02/2015        .       .       .      3625.35    20957.74

;

run;

data want;

   set have; set have(firstobs = 2 keep = trandate rename = (trandate = tran));

   if trandate = tran then call missing(dailybal,accruingbal, aggregatebal);

drop tran;

run;

proc print data = want;

format trandate ddmmyy10.;

run;

Kurt_Bremser
Super User

Sort the dataset in reverse order, then you can use the lag() function to access data that was "later" in your original sequence.

After that, re-sort to your original order.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1473 views
  • 1 like
  • 4 in conversation