Really appreciate all the feedback. Let me further clarify what I'm looking for. I have two columns, month and age, with month column already pre-sorted from 201812~201801. Age column is also already pre-sorted from smallest number to biggest number. Below is a short clip of my data set: MONTH Age (normalized) 201812 -7.60 201812 -7.17 201812 -7.14 201812 -6.05 201812 -4.85 201812 -4.67 201812 -4.67 201812 -4.23 201812 -4.15 201812 -3.99 201812 -3.50 201812 -3.07 201812 -3.01 201812 -2.48 201812 -2.19 I need a program which will read in the data set above and calculate average age by month. However, if monthly average age is smaller or equal to -0.2, it will remove the topmost data (-7.60) and recalculate the monthly average age. If it is still < or = to -0.2, it will continue removing the next topmost data (-7.17) and recalculate until finally the monthly average age >-0.2. It will then output results like below to new data set. So for example, in Dec'2018 if there are a total of 100 counts of age and 10 of the smallest numbers (10 topmost rows in age column) in that month need to be removed to achieve monthly average age >-0.2, it will output below data with ratio = 0.1 (10 out of 100). So basically, the program will fill in all the data below. MONTH Total Count Removed Count Ratio 201812 100 10 0.1 201811 201810 201809 201808 201807 201806 201805 201804 201803 201802 201801 Hope this is clear enough. Thank you.
... View more