BookmarkSubscribeRSS Feed
hhchenfx
Barite | Level 11

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;

3 REPLIES 3
Ksharp
Super User

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

hhchenfx
Barite | Level 11

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

ballardw
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 587 views
  • 0 likes
  • 3 in conversation