BookmarkSubscribeRSS Feed
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

xmastree.png

 

'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 WaveSine Wave

 

STEP 2

Transformed Sine WaveTransformed Sine Wave

3 REPLIES 3
yabwon
Meteorite | Level 14

Couldn't resist to make it "alive".

Bart

DampedOscillationXmasTree.gif

 

%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



wwvierg
Fluorite | Level 6

Sweet! Well played Bart.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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