Lapis Lazuli | Level 10

## Fun With SAS ODS Graphics - Damped Oscillation Xmas Tree

'Twas the week before Xmas, so here's a holiday card fashioned from a formula for an exponentially damped sine wave using SAS ODS Graphics. Happy Holidays, all!

``````* Fun With SAS ODS Graphics - Exponentially Damped Oscillation Xmas Tree
Reference: https://en.wikipedia.org/wiki/Q_factor;

data sinewave;                                            * Generate sine wave points;
e = constant("e");                                        * Euler's number (2.71828...);
do x=-.9 to 35 by .05;                                    * Y goes to zero at about 35;
y=e**(-0.1*x)*sin(x);                                   * Formula for damped oscillation curve (source: Wikipedia);
output;
end;

proc sql;                                                 * Rotate/flip x-axis oriented sine wave to create y-axis Xmas tree;
create table tree as select -y as x, x as y from sinewave;
* Plot the Xmas tree (series plot);
ods graphics / antialias height=6.25in width=5in;         * Size image;
ods escapechar='^';                                       * Define escape character for Unicode star above tree;
proc sgplot data=tree noborder nowall subpixel;           * Suppress chart border and wall;
styleattrs backcolor=cxE40A2D;                            * Christmas red;
title height=32pt color=white bold font="Arial Unicode MS" "^{unicode '2605'x}"; * Unicode star title;
series x=x y=y / lineattrs=(color=white thickness=5pt);   * Sine curve tree;
refline 0 / axis=x lineattrs=(color=white thickness=3pt); * Reference line tree trunk;
xaxis display=none; yaxis display=none;                   * Suppress axes;
footnote  height=6pt " ";                                 * A little padding;
footnote2 height=24pt color=white bold "Happy Holidays!"; * Holiday greeting footnote;
footnote3 height=1pt " ";                                 * A little more padding;``````

STEP 1

Sine Wave

STEP 2

Transformed Sine Wave

3 REPLIES 3
Meteorite | Level 14

## Re: Fun With SAS ODS Graphics - Damped Oscillation Xmas Tree

Couldn't resist to make it "alive".

Bart

``````%macro DampedOscillationXmasTree(i=1,n=25);

ods graphics / antialias height=6.25in width=5in;
ods escapechar='^';

ods html;

ods graphics / imagefmt=GIF;
options
papersize=('6.25 in', '5 in')
nodate nonumber
nonotes
animduration=0.12
animloop=yes
noanimoverlay
printerpath=gif
animation=start;

ods printer file="%sysfunc(pathname(work))\DampedOscillationXmasTree.gif";
ods html select none;

%do i= &i. %to &n.;
data sinewave;
e = constant("e");
do y=-.9 to 45 by .1;
x=-2**(-0.1*y)*sin(y+&i.);
output;
end;

proc sgplot data=sinewave noborder nowall subpixel;
styleattrs backcolor=cxE40A2D;
title height=32pt color=white bold
font="Arial Unicode MS" "^{unicode '2605'x}";
series x=x y=y / lineattrs=(color=white thickness=5pt);
refline 0 / axis=x lineattrs=(color=white thickness=3pt);
xaxis display=none min=-1 max=1;
yaxis display=none;
footnote  height=6pt " ";
footnote2 height=24pt color=white bold "Happy Holidays!";
footnote3 height=1pt " ";
run;
%end;

ods html select all;
options
notes
printerpath=gif
animation=stop;
ods printer close;

%mend DampedOscillationXmasTree;

%DampedOscillationXmasTree()``````
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation

Fluorite | Level 6

## Re: Fun With SAS ODS Graphics - Damped Oscillation Xmas Tree

Sweet! Well played Bart.

Fluorite | Level 6

## Re: Fun With SAS ODS Graphics - Damped Oscillation Xmas Tree

LIKE!!
Discussion stats
• 3 replies
• 723 views
• 22 likes
• 3 in conversation