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

HereComesPeterCottontail.gif

 

Q. What do you get when you combine Easter Bunny plot point data (189 line segments) lifted from http://math-aids.com and code lifted from Sanjay Matange's Animation using SGPLOT blog post?

A. HereComesPeterCottontail.gif!

 

EASTERBUNNY.SAS

/* File contains points to plot from http://math-aids.com */
filename Bunny "/folders/myfolders/EasterBunny.txt";

data EasterBunny(keep=shapeID x y);
length shapeID $ 20. x 8 y 8;
retain shapeID;
infile Bunny lrecl=1000;
input;
if _infile_=:'Shape' then
  shapeID=_infile_;
else
  do;
    i=1;
    do while(scan(_infile_, i, '(), ')^='');
      x=scan(_infile_, i, '(), ');
      y=scan(_infile_, i+1, '(), ');
      i+2;
      output;
    end;
  end;

data line(keep=function drawspace x1 y1 x2 y2);
set EasterBunny;
by shapeID notsorted;
function='line';
drawspace='datavalue';
x1=lag(x);
y1=lag(y);
x2=x;
y2=y;
if ^first.shapeID;

proc template;
define statgraph ebtemplate;
  begingraph;
    dynamic linenum;
    layout overlayequated / xaxisopts=(griddisplay=on) yaxisopts=(griddisplay=on);
      scatterplot x=x y=y / markerattrs=(size=0);
      entry halign=right linenum / valign=bottom textattrs=(size=36 weight=bold color=lightgray);
      annotate;
    endlayout;
  endgraph;
end;
run;

* Create animated GIF with one incremental plot for each line;

ods _all_ close;
options papersize=('4 in', '4 in') printerpath=gif animation=start 
        nodate nonumber animduration=.06 animloop=YES NOANIMOVERLAY;
ods printer file='/folders/myfolders/Bunny/HereComesPeterCottontail.gif';
ods graphics / width=4in height=4in imagefmt=GIF;

%macro drawlines; 
proc sql noprint;
select count(*) into :numlines from line;
quit;
%do l=1 %to 20;         * Display final image before drawing lines;  
  proc sgrender data=easterbunny template=ebtemplate sganno=line;
  dynamic linenum=" "; 
%end;
%do l=1 %to &numlines;  * Draw incremental image with lines thus far;  
  proc sgrender data=easterbunny template=ebtemplate sganno=line(obs=&l);
  dynamic linenum="&l";
%end;
run; 
%mend;

%drawlines;
options printerpath=gif animation=stop;
ods printer close;

 

EASTERBUNNY.TXT 

Shape 1
(10,25) , (9,27.5) , (8.5,29) , (8,30.5) , (8,31) , (8,31.5) , (8.5,32) , (9.5,31.5) , (10,30.5)
(11,29.5) , (12,29) , (13,27.5) , (13,26) , (11,26) , (10,25)
Shape 2
(11,26) , (10,28) , (9,29.5) , (8.5,30.5) , (8,31)
Shape 3
(13,26) , (13.5,26) , (14.5,26) , (15.5,25.5) , (17,26.5) , (18.5,27) , (19.5,28)
(20,29) , (17,27.5) , (15.5,27) , (14.5,26)
Shape 4
(13.5,26) , (14,27.5) , (15,28.5) , (16,29) , (18,29.5) , (20,30) , (20.5,29.5)
(20.5,27.5) , (19.5,26.5) , (18,25.5) , (16.5,25.5) , (16,25) , (15.5,25.5)
Shape 5
(9.5,22) , (10,22) , (11,22) , (11,23) , (10.5,23.5) , (10,22) , (10,23.5)
(10.5,24) , (11.5,24) , (11,22) , (11.5,22)
Shape 6
(11.5,22) , (12,22.5) , (13,22.5) , (14,22) , (14.5,22) , (16,22) , (15.5,23) , (15.5,23.5)
(15,23) , (14.5,22) , (14.5,22.5) , (15,24) , (16,23.5) , (16,22) , (16.5,21.5)
Shape 7
(11.5,22) , (10.5,21.5) , (11,20.5) , (11.5,20) , (12,20) , (12.5,19.5) , (13,19.5)
(13.5,20) , (12.5,20.5) , (12,20)
Shape 8
(12.5,20.5) , (12.5,21) , (12,21.5) , (12.5,22) , (13.5,21.5) , (12.5,21)
Shape 9
(11.5,20) , (12,19) , (13,18.5) , (13.5,19) , (14,20) , (13.5,20)
Shape 10
(14,20) , (14.5,20.5) , (15,21) , (14,22)
Shape 11
(12,18) , (13,17.5) , (13.5,18)
Shape 12
(10,25) , (9.5,24) , (9,23) , (8.5,22) , (7.5,21.5) , (7.5,20.5) , (8,19) , (9.5,17.5)
(11,17) , (12.5,16.5) , (13.5,16.5) , (15,17) , (16.5,17.5) , (17.5,18) , (18,19)
(18.5,20) , (18.5,20.5) , (18,21.5) , (17.5,22.5) , (17,23.5) , (16.5,24.5) , (16,25)
Shape 13
(9.5,17.5) , (8.5,16) , (8,14.5) , (7.5,15) , (7,14) , (7.5,14) , (8,13) , (8,14.5)
Shape 14
(10.5,16.5) , (12,16) , (14,16) , (15,16) , (15.5,15.5) , (16,15) , (16,14) , (14.5,14.5)
Shape 15
(16,14) , (15.5,13) , (15,12.5) , (14.5,12.5) , (13,14)
Shape 16
(14.5,12.5) , (13.5,12) , (13,12.5) , (12,13.5)
Shape 17
(13,12.5) , (12,13) , (10,12) , (9.5,14) , (8,13)
Shape 18
(15,16) , (15.5,17) , (16.5,17.5) , (18,17) , (18.5,16.5) , (19,15.5) , (19.5,14) , (18.5,14.5) , (19,15.5)
Shape 19
(18.5,14.5) , (18,14.5) , (18.5,16)
Shape 20
(18,14.5) , (17,14.5) , (17,16.5)
Shape 21
(17,14.5) , (16.5,15) , (15.5,15.5) , (16.5,17)
Shape 22
(7,14) , (6.5,11.5) , (6.5,10.5) , (12,10) , (14,10) , (17,10.5) , (19,11.5)
(20.5,12.5) , (19.5,15) , (19,15.5)
Shape 23
(6.5,10.5) , (7,9) , (9,8.5) , (12,8) , (16,8.5) , (19,9.5) , (20.5,10.5) , (20.5,12.5)
Shape 24
(7,9) , (7.5,7) , (9,4.5) , (10,4.5) , (11,5) , (12.5,4.5) , (13.5,4)
(15,5) , (16.5,4) , (19,6) , (20,7.5) , (20.5,9.5) , (20.5,10.5)
Shape 25
(9,4.5) , (10,3.5) , (11,4) , (13.5,3) , (15,4) , (16,3.5) , (17,3.5) , (18.5,5) , (19,6)
Shape 26
(10,3.5) , (13,2.5) , (14,2.5) , (16,3) , (17,3.5)

 

1 REPLY 1
MichelleHomes
Meteorite | Level 14

Talk about pulling a rabbit out of a hat Man Wink 

 

Love your creativity! Well done.

 

Kind Regards,

Michelle

 

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1 reply
  • 7483 views
  • 3 likes
  • 2 in conversation