jiri jansa
jiri jansa

Reputation: 159

SAS - percentile from row

I have a dataset with one base variable and 1000 generated. The base variable is ps_a_pc, the scenarios are called ps_a_var1...ps_a_var1000.

The dataset is as follows:

 ps_a_pc ps_a_var1 .... ps_a_var1000
    0       1      ....    5
    3       6      ....   14

Now I would like to calculate for each row its minimal value, maximal value and percentiles (20%,40%,60%,80%).

It is easy to get maximal and minimal value:

data MinMaxRows;
     set mydata.tot_i;
array x [1000] PS_a_var1-PS_a_var1000;
min = min(of x[*],ps_a_pc);
max = max(of x[*],ps_a_pc);
run;

but is there any simple way how to get percentiles for each row ? The only solution coming to my mind is to transpose the dataset and calculate it using univariate function.

Thank you for any suggestion.

Upvotes: 2

Views: 1361

Answers (2)

Richard
Richard

Reputation: 27498

Jiri:

Look at the PCTL() function.

Upvotes: 1

ocstl
ocstl

Reputation: 386

You can use the PCTL function.

data want;
    set have;
    pct80 = pctl(80, of ps_a_var1-ps_a_var1000);
run;

Obviously, adjust the '80' value as required for the other percentiles.

Upvotes: 1

Related Questions