How to delete observations in SAS

SAS: Make up to the loop and delete observations - arrays, loops, sas

My dataset contains the following variables:


First I want to create a new variable "Ratio" = Sum (Actual) / Sum (Expected). For the first observation, I want this expression to contain all of the values โ€‹โ€‹of Actual and Expected. For the second iteration, I want to repeat this expression with just the second observation and on. Then for the third iteration I want to include the third observation and on.

This is an example of the data and formula as it would look in Excel.

Second, the record could be any number of times, so I want the expression to continue until the "ratio" is below a value I manually set. Ideally, the program also includes the creation of a fourth variable with the number of observations that are excluded from the printout. For the first observation it would be "0", the second observation "1", the third observation "2" and so on.

I think that will need an array too? Thanks in advance.


0 for the answer โ„– 1

They are requesting that code be written for you, English: That's off-topic (instead of asking for help with the code you wrote ), But you may have an interesting technical question or ask a new one.

What you want to do here is sort your data in reverse if possible. If there is no sorting, you can either add an observation counter:

Or you can use POINT to reverse your order of record, although this is a little slower. This is the basic form of the latter technique. If you can reverse the order, you don't need the do loop or the set options.

From here, you should be able to clear the rest of your question. You will of course have to re-sort using the correct sorting method afterwards.