Data visualization with SAS programming

Fun w/SAS ODS Graphics: New Year's Eve Ball Drop

Reply
Contributor tc
Contributor
Posts: 67

Fun w/SAS ODS Graphics: New Year's Eve Ball Drop

HappyNewYear.gif

 

A quick black-and-white ODS Graphics take on the Times Square New Year's Eve ball drop (hat tip to Rick Wicklin for the BY-statement trick!). Happy New Year's!

 

CODE

* Fun w/SAS ODS Graphics: B&W New Year's Eve Ball Drop;
 
*==> Generate and render data for frames showing ball dropping w/countdown timer;

data HappyNewYear;                                     * Generate points/text for ball drop & countdown timer;
x=.5; x1=.5;                                           * X-values of ball, countdown text are constant;
x1=.5; y1=.5; y2016=2016;                              * Coordinates and label for countdown timer;
do frameid=1 to 0 by -.01;                             * Generate data for frames (ball position + timer text);
  if frameid>.0001 then text=compress(put(ceil(frameid*10),2.)); else text='';
  y=frameID;
  r=50;                                                * Relative size of ball for bubble plot;  
  output; 
  y=.; r=1; output;                                    * Generate small "dummy" point to make ball bigger; 
end;
run;

options nobyline;                                      * Animated GIF initialization;
ods _all_ close;
options papersize=('5 in', '5 in') printerpath=gif animation=start 
        nodate nonumber animloop=YES animduration=.1 NOANIMOVERLAY ;
ods printer file='/folders/myfolders/HappyNewYear/HappyNewYear.gif';
ods graphics / width=5in height=5in imagefmt=GIF border=off;

proc template;                                         * Display ball (bubbleplot) & countdown timer (textplot);
define statgraph newyearplot1;
begingraph / opaque=true border=false drawspace=layoutpercent backgroundcolor=black;
  layout overlayequated / equatetype=square border=false  
         WALLDISPLAY=NONE commonaxisopts=(viewmin=-.15 viewmax=1.15 tickvaluelist=(-.15 1.15)) 
         xaxisopts=(display=none OFFSETMAX=0 OFFSETMIN=0) yaxisopts=(display=none OFFSETMAX=0 OFFSETMIN=0);
    textplot x=x1 y=y1 text=text / position=center textattrs=(size=232pt color=grey) contributeoffsets=none;     
    bubbleplot x=x y=y size=r / datalabel=y2016 datalabelposition=center 
               datalabelattrs=(color=black weight=bold size=20pt)
               dataskin=sheen colormodel=(WHITE) colorresponse=x bubbleradiusmax=40;        
  endlayout;
endgraph;
end;

proc sgrender data=happynewyear template=newyearplot1; * Generate one frame for each position of ball;
by frameID notsorted;

*==> Generate and render data for Happy New Year! frames;

data happynewyear2;                                    * Generate points/text;
x1=.5; y1=.5; text1="Happy*New Year!";
x2=.5; y2=0;  text2="2017"; 

%macro genframes(duration=,backlight=);                * Vary backlighting/duration to make words "flash";
options animduration=&duration;

proc template;
define statgraph newyearplot2;
begingraph / opaque=true border=false drawspace=layoutpercent backgroundcolor=black;
  layout overlayequated / equatetype=square border=false  
         WALLDISPLAY=NONE commonaxisopts=(viewmin=-.15 viewmax=1.15 tickvaluelist=(-.15 1.15)) 
         xaxisopts=(display=none OFFSETMAX=0 OFFSETMIN=0) yaxisopts=(display=none OFFSETMAX=0 OFFSETMIN=0);
    textplot x=x1 y=y1 text=text1 / position=top backlight=&backlight splitchar='*' splitpolicy=splitalways
                                    textattrs=(size=42pt weight=bold) contributeoffsets=none;
    textplot x=x2 y=y2 text=text2 / position=center backlight=&backlight splitchar='*' splitpolicy=splitalways
                                    textattrs=(size=42pt weight=bold) contributeoffsets=none;             
  endlayout;
endgraph;
end;

proc sgrender data=happynewyear2 template=newyearplot2;
run;
%mend;

%genframes(duration=.5,backlight=1);                  * Alternate bright/dim for "flashing" effect;
%genframes(duration=.5,backlight=.5);
%genframes(duration=.5,backlight=1);
%genframes(duration=.5,backlight=.5);
%genframes(duration=.5,backlight=1);
%genframes(duration=.5,backlight=.5);
%genframes(duration=3,backlight=1);

options printerpath=gif animation=stop;             * Wrap-up animated GIF creation;                         
run;
ods printer close;
Community Manager
Posts: 2,596

Re: Fun w/SAS ODS Graphics: New Year's Eve Ball Drop

Thanks for squeezing in one more cool ODS Graphics trick, @tc! Happy New Year!

Super User
Posts: 1,203

Re: Fun w/SAS ODS Graphics: New Year's Eve Ball Drop

Nice count down @tc! Will this be your next dataviz? www.linkedin.com/hp/update/6221188723963359232

Contributor tc
Contributor
Posts: 67

Re: Fun w/SAS ODS Graphics: New Year's Eve Ball Drop

It is a nice effect - perhaps I should submit a SASware Ballot idea for a CIRCULARDOTPLOT SGPLOT statement.  :-)

Occasional Contributor
Posts: 14

Re: Fun w/SAS ODS Graphics: New Year's Eve Ball Drop

Another nice piece of work by Ted, BUT . . .

what happened to the Leap Second?

Or is it added to 2017 AFTER the ball drop completes?

Post a Question
Discussion Stats
  • 4 replies
  • 1636 views
  • 15 likes
  • 4 in conversation