Programming the statistical procedures from SAS

How to create multiple kernel distributions in one graph

Reply
Occasional Contributor
Posts: 5

How to create multiple kernel distributions in one graph

Dear community

This is my first post so I appologize if I make some rookie mistakes like placing the question in a wrong place or something like that.

I have a hopefully simple request, i have made a kernel distribution for a number of years by using proc kde and i wanna have them all in the same graph.

Does anyone know a option which can be used? I've looked through the documenation for proc kde, but for me it doesn't seem like the options is there.

Best regards,

zuki

SAS Super FREQ
Posts: 3,319

How to create multiple kernel distributions in one graph

Welcome! Thanks for a great question!

It sounds like you have variables such as Y2000-Y2011 which represent different yearly measurements of some quantity. You can use the PLOTS=densityoverlay option to overlay the densities of all of these onto a single plot. Here is an example of overlaying two densities in a SASHELP data set:

/* use KDE to overlay estimates of different variables */

proc kde data=sashelp.cars;

   univar mpg_city mpg_highway / plots=densityoverlay;

run;

Occasional Contributor
Posts: 5

How to create multiple kernel distributions in one graph

Hi Rick!

Thank you very much for your reply. I think we are almost there but that I was a bit unclear with my formulation.

Ehm so to elaborate: I have a dataset with one observation per firm (variable: lbnr) per year (variable: year) with a variable for how much they grow in percent (emp_growth) and a variable for how many employees they have in average (emp_avg), so I wanna do the kernel distribution for emp_growth for each value of year in 2007-2009 with emp_avg as weight.

I am no expert in proc kde, but for me to see you code doesn't know the role of the year variable, but i definetely could be just misunderstanding you.

SAS Super FREQ
Posts: 3,319

How to create multiple kernel distributions in one graph

Sort by year.Then use YEAR as a BY variable and use the OUT= option to save the kernel densities to an output data set. You can use the SERIES statement in PROC SGPLOT to overlay the curves.

If you don't want them overlaid, but are content with a panel, you can use PROC UNIVARIATE.  In this case, use YEAR as a CLASS statement. See this example: http://support.sas.com/documentation/cdl/en/procstat/63963/HTML/default/viewer.htm#procstat_univaria...

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