BookmarkSubscribeRSS Feed
Vasilis
Calcite | Level 5

nHi everyone. This is my first post. First of all, it is good to be part of this Community!

I have a problem with sas coding. I want to fit a distribution (eg Normal or Lognormal) to some data and take the percentiles. I am using the following code which is fine.

My problem is that i want to extract the P99 of the fitted data at a sas data and not only at the results.

PROC UNIVARIATE DATA = WORK.TEMP1 NOPRINT ;*pctldef=5;

BY RESERVING_LOB_LOCAL;

VAR log_max_incurred;

HISTOGRAM   log_max_incurred /  NOPLOT LOGNORMAL ( W=1  L=1  COLOR=YELLOW  ZETA=EST THETA=0 SIGMA=EST);

OUTPUT OUT=FINAL2 p99=P99 ;

RUN;

By doing this i save at the sas data "final2" only the p99 of the actual data and not of the fitted data too.

Can you please help me?

Thank you very much in advance! Vasilis.

8 REPLIES 8
PaigeMiller
Diamond | Level 26

I think you have to use the OUTHIST= option to get that (and it may not be exactly the 99 percentile). You could always take the estimated coefficients of the Lognormal model and compute exactly where the 99 percentile is.

--
Paige Miller
Vasilis
Calcite | Level 5

Thanks, i will try the outhistogram option. However, i would like to get the exact 99 percentile of the fitted data. Can you please give me some more help about yur second proposal? Maybe i don't understand very well but how can i calculate the estimated coefficients?

PaigeMiller
Diamond | Level 26

Vasilis wrote:

Thanks, i will try the outhistogram option. However, i would like to get the exact 99 percentile of the fitted data. Can you please give me some more help about yur second proposal? Maybe i don't understand very well but how can i calculate the estimated coefficients?

You are specifying a lognormal distribution, and the parameter estimates are calculated by PROC UNIVARIATE, so then you should program the lognormal distribution in a DATA step or otherwise, using these parameters, and find the exact 99%-lie point.

Or as Xia Keshan said, you can read these percentage points from a PPPlot

--
Paige Miller
Vasilis
Calcite | Level 5

In both cases i have to read something first in order to move on. That is not something i want! (I can already read it from the histogram) I want to use the percentile as an input so i need it in sas data form! Thanks!

PaigeMiller
Diamond | Level 26

I guess I'm not really grasping the problem here.

If you run PROC UNIVARIATE, you can obtain the estimates of the lognormal coefficients. Use ODS OUTPUT PARAMETERESTIMATES=PARAMS; This will give you a SAS data set with the estimates of the Lognormal distribution. From there, you program the distribution using the Lognormal formula, in a SAS data step to determine the 99%-ile point.

As stated in the SAS documentation (click to enlarge so it is readable):

SAS Help and Documentation_2015-04-29_10-52-52.gif

--
Paige Miller
Reeza
Super User

Welcome to the forums Smiley Happy

If you get a table in the results window that you want as a SAS data set you need to find the name using ODS TRACE.

The table name for the quantiles if FITQUANTILES.

Using the SASHELP.CARS dataset I think this is what you want.

ods table fitquantiles=mpg_city_quantiles;

PROC UNIVARIATE DATA = sashelp.cars NOPRINT ;

VAR mpg_city;

HISTOGRAM   mpg_city /  NOPLOT LOGNORMAL ( W=1  L=1  COLOR=YELLOW  ZETA=EST THETA=0 SIGMA=EST);

RUN;

proc print data=mpg_city_quantiles;

run;

A blog post on the topic:

How do I get my SAS results into a data set? | Statistics and other stuff from a geek

Ksharp
Super User

Not sure . Did you check PPPlot or QQPlot statement ?

Vasilis
Calcite | Level 5

I need the quantiles of the fitted data...so first i have to fit the data to the distribution i am interested in and then extract the quantiles at a sas data. With the code that you can see above i can do all of this except the part of extraction to a sas data. Is there a another way to fit some data to a distribution? I only know this method with the histogram inside a proc univariate..

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 1312 views
  • 0 likes
  • 4 in conversation