Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
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
Onyx | Level 15

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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