BookmarkSubscribeRSS Feed
Rick_SAS
SAS Super FREQ

I'm sure @tc will post an awesome Christmas-themed graphic soon, but you can enjoy this one until he does:

 

normalTree4.png

 

/* A normal Christmas tree: Each branch is a normal PDF (shaded) */
data NormalTree;
array x[101];    /* for efficiency, store (x, phi(x)) values in an array */
array phi[101];
 
/* compute the standard normal PDF on [-xMax,xMax] */
xMax = 2.5;
dx = 2*xMax / (dim(x)-1);        /* step size for x */
do i = 1 to dim(x);
   x[i] = -xMax + (i-1)*dx;      /* the i_th point in [-xMax,xMax] */
   phi[i] = pdf("Normal", x[i]); /* phi(x) is normal PDF */
end;
 
b = 4;     /* width of the tree base; the interval is [-b/2, b/2] */
h = 6;     /* height of tree; the interval is [0, h] */
nSegs = 8; /* number of normal curves to overlay to construct the tree */
 
/* linear transformation of Y from [0,maxPhi] to [0, 2*dy]. Use for ALL branches. */
maxPhi = pdf("Normal", 0);
dy = h / (nSegs+1);  /* height of each normal curve */
do i = 1 to dim(x);
   phi[i] = 2*dy / maxPhi * phi[i];
end;
 
/* Translate curve and baseline up by k*dy units.
   Linearly transform X from [-xMax,xMax] to [-xR, xR].
   If you slice the right triangle with base b/2 and height h 
   at L=k*dy, the width of the slice is xR = (b/2)/h * (h-L) */
do k = 0 to nSegs-1;
   baseline = k*dy;
   xR = (b/2)/h * (h - baseline);
   do i = 1 to dim(x);
      t = xR / xMax * x[i];   /* t is the scaled version of X for k_th branch */
      y = baseline + phi[i];  /* vertically translate Y values */
      output;
   end;
end;
keep k i baseline t y;
run;
 
/* Fill/shade the PDF: https://blogs.sas.com/content/iml/2015/07/20/density-shaded-tails.html */
ods graphics / width=480px height=480px;
title "A Normal Christmas Tree";
proc sgplot data=NormalTree noautolegend aspect=1 noborder;
  band x=t upper=y lower=baseline / group=k fill fillattrs=(color=DarkGreen) outline lineattrs=(color=black);
  xaxis display=none;
  yaxis display=none;
run;


How did he do that? See https://blogs.sas.com/content/iml/2024/12/16/normal-christmas-tree.html 

And I acknowledge @Ksharp for his inspiration last year.

1 REPLY 1
Ksharp
Super User

Rick,

I have already read your blog .GREAT !

I think you should rename this post as 
Fun With SAS ODS Graphics: A normal Christmas tree

to make @tc    notice it .

 

Ksharp_0-1734486617018.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 753 views
  • 8 likes
  • 2 in conversation