Data visualization with SAS programming

Turn Histogram into a Line Graph - With Markers

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 115
Accepted Solution

Turn Histogram into a Line Graph - With Markers

I have been searching for a long time for the correct code to do this, but I have not found it yet. I have n = 20,000 cases. I have already sorted the order of the data by RESERVE from low to high. Basically I would like to see how all 20,000 records distribute with either the count or the % on the y-axis. No need for another variable. Sort of a very big histogram turned into a line graph.

Then, to add a little complexity to it, I would like to mark a few points on the graph. Currently my RESERVE variable goes from 100 to about 5 million. But it would be nice if I could denote where 100,000 is, or where 20,000 is in my distribution.

Thank you very much in advance.


Accepted Solutions
Solution
‎08-25-2015 08:34 AM
SAS Super FREQ
Posts: 864

Re: Turn Histogram into a Line Graph - With Markers

You might want to consider using a kernel density estimate instead of a histogram. Run these two programs and compare the output:

proc sgplot data=sashelp.heart;

histogram weight;

run;

proc sgplot data=sashelp.heart;

density weight / type=kernel scale=percent;

run;

View solution in original post


All Replies
Solution
‎08-25-2015 08:34 AM
SAS Super FREQ
Posts: 864

Re: Turn Histogram into a Line Graph - With Markers

You might want to consider using a kernel density estimate instead of a histogram. Run these two programs and compare the output:

proc sgplot data=sashelp.heart;

histogram weight;

run;

proc sgplot data=sashelp.heart;

density weight / type=kernel scale=percent;

run;

Frequent Contributor
Posts: 115

Re: Turn Histogram into a Line Graph - With Markers

Thank you very much Dan. Unfortunately my data is a bit on the side of being "super skewed." So I use the following code to graph it when I break my full distribution into 100 bins. The graph is much more healthy looking. Any suggestions on how to get markers in here to denote particular breaks in the distribution?

proc rank data = CLAIMS_DATA out = CLAIMS_DATA groups = 100;
   var TRENDED_INCURRED;
   ranks B_TRENDED_INCURRED;
run;

ods output "Summary statistics"=STATS;
proc means data = CLAIMS_DATA mean;
  var TRENDED_INCURRED;
  class B_TRENDED_INCURRED;
run;
quit;
ods output close;

proc sgplot data = STATS;
  series x = B_TRENDED_INCURRED Y = TRENDED_INCURRED_Mean;
run;

SAS Super FREQ
Posts: 864

Re: Turn Histogram into a Line Graph - With Markers

You could put those break points in a separate data set and merge it back into the original. Then, just add a scatter overlay to your series plot referencing  those two columns.

Frequent Contributor
Posts: 115

Re: Turn Histogram into a Line Graph - With Markers

Thanks. Feel free to send along the code to accomplish this, if you wish. I have never even remotely tried to pull something like that off.

Post a Question
Discussion Stats
  • 4 replies
  • 352 views
  • 7 likes
  • 2 in conversation