Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Proc univariate: save value of 99th percentile

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-22-2016 04:00 PM

Hi,

I want to obtain a numerical value for the 99th percentile to use later in a data step. I think it can be done in a number of ways, but ulitmately I am winsorizing my cohort. I.e., for anyone with costs greater than the 99th percentile, set their cost equal to the 99th percentile value.

This is what i have so far:

proc univariate data = mydata;

where age_18 = 1;

class &var1;

var cost;

run;

/* --> I want out output the 1st and 99th percentile *values. *Where do I "output" this value? I dont necessarily need a whole data set, just 1 number.*/

data mydata2;

set mydata;

if cost > {99th percentile value} then cost_2 = {99th percentile value};

if cost < {1st percentile value} then cost_2 = {1st percentile value;

run;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ly2105

08-22-2016 04:14 PM

Hi:

The SAS Documentation for PROC UNIVARIATE seems to have a relevant example on how to save percentiles into an output dataset:

http://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_univaria...

And then, once you have the percentiles in an output dataset, you could make macro variables that can be used in subsequent steps.

cynthia

The SAS Documentation for PROC UNIVARIATE seems to have a relevant example on how to save percentiles into an output dataset:

http://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_univaria...

And then, once you have the percentiles in an output dataset, you could make macro variables that can be used in subsequent steps.

cynthia

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ly2105

08-23-2016 10:03 AM

As Cynthia says, use the OUTPUT statement and specify the P1= and P99= keywords:

```
proc univariate data=sashelp.cars noprint;
class origin;
var MPG_City;
output out=PctlOut P1=P1 P99=P99;
run;
proc print; run;
```

You could also use PROC MEANS with the same syntax.

If you have multiple variables, see the article "Output percentiles of multiple variables in a tabular format."