Program example to compute a PDF as a numerical derivative of a CDF.
==================================================================================
options linesize = 80 ;
footnote "~john-c/5421/sasprog.sas &sysdate &systime" ;
FILENAME GRAPH 'gsas.grf' ;
LIBNAME loc '' ;
OPTIONS LINESIZE = 80 MPRINT ;
GOPTIONS
RESET = GLOBAL
ROTATE = PORTRAIT
FTEXT = SWISSB
DEVICE = PSCOLOR
GACCESS = SASGASTD
GSFNAME = GRAPH
GSFMODE = REPLACE
GUNIT = PCT BORDER
CBACK = WHITE
HTITLE = 2 HTEXT = 1 ;
*===================================================================== ;
/* Program illustrating how to find a pdf, given the cdf ... */ ;
data cdfpdf ;
pi = 4*atan(1) ;
x = 1 ;
h = 1e-7 ;
cdfx = probnorm(x) ;
fderivx = (probnorm(x + h) - probnorm(x)) / h ;
pdfx = (1/sqrt(2 * pi))* exp(-x*x/2) ;
output ;
run ;
proc print data = cdfpdf ;
run ;
/* How to graph a pdf ... */ ;
data pdfgraph ;
n = 400 ;
h = 1e-7 ;
do i = 1 to n ;
x = -3 + 6 * i / n ;
cdf = probnorm(x) ;
pdf = (probnorm(x + h) - probnorm(x)) / h ;
output ;
end ;
run ;
symbol1 i = j v = none w = 8 h = 8 l = 1 c = ligrey ;
symbol2 i = j v = none w = 8 h = 8 l = 3 c = black ;
proc gplot data = pdfgraph ;
plot cdf * x pdf * x / overlay ;
title1 h = 2 'Graph of the Standard Normal CDF (grey) and PDF (black)' ;
title2 h = 2 'Based on Numerical Approximation of the PDF' ;
title3 h = 2 'As a derivative of the CDF' ;
run ;
endsas ;
==================================================================================
/home/gnome/john-c/5421/derivative.sas Most recent update: Sep 29, 2010