Skip to content

Instantly share code, notes, and snippets.

@Benjit87
Last active December 10, 2015 02:28
Show Gist options
  • Save Benjit87/4367284 to your computer and use it in GitHub Desktop.
Save Benjit87/4367284 to your computer and use it in GitHub Desktop.
/*
Inspired by Rick Wicklin's <a href="http://blogs.sas.com/content/iml/2012/12/14/a-fractal-christmas-tree/">SAS Christmas Tree</a>, i decided to create my own tree using Base SAS to generate the data and then using JMP to visualize the data in bubbleplot.
http://benjithian.sg/2012/12/sas-jmp-christmas-tree/
*/
/* Snow generator */
%macro snow_generator(density,filename);
data snow;
drop i;
do i = 1 to &density;
y1 = rand('UNIFORM') * 100;
x1 = rand('UNIFORM') * 100 - 20;
tone = "101";
time = 1;
size = 10;
type = "snow";
output;
end;
run;
proc append base=&filename
data=snow;
run;
%mend snow_generator;
/*Create the triangle*/
%macro drawtri(filename,displacement,width);
data triangle;
length tone $10;
drop x y displacement width;
displacement = &displacement;
width = &width;
do y = 1 to &width;
do x = y to width;
y1 = y + displacement;
x1 = x + (50-&width)/2;
tone = "100";
time = 1;
size = 100;
type = "leaf";
output;
end;
width = width - 1;
end;
run;
proc append base=&filename
data=triangle;
run;
%mend drawtri;
/*Decorate the tree*/
%macro decoration(filename,displacement,width);
data decorate;
length tone $10;
drop x y displacement width rng;
displacement = &displacement;
width = &width;
do y = 1 to &width;
do x = y to width;
y1 = y + displacement;
x1 = x + (50-&width)/2;
rng = rand('UNIFORM');
tone = "100";
time = 1;
size = 50;
type = "leaf";
if rng > 0.90 then do;
rng = round(rng * 100,1) + 300;
tone = put(rng,$3.);
output;
end;
end;
width = width - 1;
end;
run;
proc append base=&filename
data=decorate;
run;
%mend decoration;
/* How high u want your tree to be */
%macro BuildTree(counter);
%do i = 1 %to &counter;
/*Make the triangle shorter each time and higher*/
%drawtri(tree,%eval(&i*15),%eval(50-&i*5))
%decoration(tree,%eval(&i*15),%eval(50-&i*5))
%end;
/*Create rectangle (tree trunk)*/
data stump;
length tone $10;
do x1 =20 to 30;
do y1 = 0 to 10;
tone = "1";
time = 1;
type = "trun";
output;
size = 50;
end;
end;
run;
proc append base=tree
data=stump;
run;
/*Generate Snow*/
%snow_generator(100,tree)
data tree;
set tree;
id = _N_; *create id for tree;
run;
%mend BuildTree;
%macro SimulateSnow(time);
data snowtree;
set tree;
time = &time;
if type = "snow" then
do;
y1 = rand('UNIFORM') * 100;
x1 = rand('UNIFORM') * 100 - 20;
end;
run;
proc append base=finaltree data=snowtree;
run;
%mend SimulateSnow;
/* main program */
%macro ChristmasTree;
%BuildTree(5) /* Build the tree with height 5 */
%do i = 1 %to 10;
%SimulateSnow(&i);
%end;
%mend ChristmasTree;
/* START */
%ChristmasTree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment