Help with moving percentile based on current information

Reply
Super Contributor
Posts: 371

Help with moving percentile based on current information

Hi Everyone,

I have a data with 2 variables value and N (N is the lag step used below)

For each record (i), I have to calculate the Change= value – lagN(value) for the prior 10 record. The N step is the N of current record.

So the below is how the calculation is done for record  11th (with lag step =2). the 3rd column is lag2 value, the 4th column is the change.

Then I have to find the percentile of current change among these prior 10 prior change value.

(the most challenging part for me is to create a sub group for each record to do the rank, In practice, I have to find the percentile based on the prior 500 record)

Could you please help me to do that?

Thank you so much.

HHC

  2 2  .

  3 3  .

  9 4 9-2=7

  4 6 3 4-3=1

  5 8 9

  6 9 4

  7 1 5

  8 5 6

  6 2 7

  7 8 8

  8 2 6

--------------------------

data have;

  input value N;

  datalines;

  2 2

  3 3

  9 4

  4 6

  5 8

  6 9

  7 1

  8 5

  6 2

  7 8

  8 2

  3 4

  9 6

  0 9

  6 4

  4 8

  9 9

  8 3

  7 3

  4 4

  5 7

  4 5

  32 2

  21 1

  23 2

  4 3

  5 4

  6 6

  7 8

  8 2

;run;

Super User
Posts: 9,691

Re: Help with moving percentile based on current information

Can't use PCTL Function to get it ? What does your output look like ?

Super Contributor
Posts: 371

Re: Help with moving percentile based on current information

Hi Xia,

For each record, in the output we should have a new percentile collumn.

the difficulty for me is that the percentile of record ( i ) is built on the difference with lag step ( i )

I will create a spreadsheet when i get my laptop with me.

Thank you,

HHC

Super User
Posts: 10,552

Re: Help with moving percentile based on current information

You also may want to look at the DIFn function. Does the Lag and subtraction as one function.

And you only need the first variable from what you are showing.

If I understand what you may be looking for:

data want;

     set have;

     col2=dif2(n);

     col3=dif3(n);

     col4=dif4(n);

     col5=dif5(n);

     col6=dif6(n);

     col7=dif7(n);

     col8=dif8(n);

     col9=dif9(n);

     col10=dif10(n);

run;

Ask a Question
Discussion stats
  • 3 replies
  • 215 views
  • 0 likes
  • 3 in conversation