data WORK.have; input DATE1 :DATE9. DATE2 :DATE9. ID:4. ROLL:2. NUM:3. AMOUNT:2.; datalines; 01JAN2022 20APR2022 1411 69 115 1 01FEB2022 30JAN2022 1411 69 115 2 01FEB2022 30JAN2022 1411 69 115 3 03MAR2022 21FEB2022 1412 70 116 1 04MAR2022 29JAN2022 1412 70 116 2 ;;;; Here's the data step code of the dataset. The records were sorted based on date1, DATE2, id, roll, num and the primary keys for this dataset is id, roll, num. Based on these 3 variables the data is inter linked with eachother. When comes to what I require is I require the rows of 1st appearance of Id, roll, num only when the DATE1 is >= DATE2. This DATE1 >= DATE2 should apply only when the 1st appearance of Id, roll, num. If this fails, please keep an OR condition by saying the amount values should be compared to prior and next value of eachother and when there's an increase in the amount variable values then the row which has max amount value should be picked and it must meet the base condition which is DATE1 >= DATE2. Example : 01JAN2022 20APR2022 1411 69 115 1 01FEB2022 30JAN2022 1411 69 115 2 01FEB2022 30JAN2022 1411 69 115 3 03MAR2022 21FEB2022 1412 70 116 1 04MAR2022 29JAN2022 1412 70 116 2 In the given example above, the DATE1 value is not >= DATE2 for the 1st appearance of Id, roll, num so, it fails then for the next two values the amount is increased i.e 1,2,3 so, for this case the max amount value which is 3 that row should be picked and also the base condition is met 01FEB2022 >= 30JAN2022. This is one iteration. For the 2nd iteration i.e as the id, roll, num is changed that's why I said it as 2nd iteration. So, in the 2nd iteration the 1st appearance of Id, roll, num(i.e 1412 70 116) met the basic condition i.e 03MAR2022 >= 21FEB2022 this row should be picked. once this condition is pass, it shouldn't go to OR condition. I hope this makes sense to y'all. Thankyou.
... View more