Learning SAS? Welcome to the exclusive online community for all SAS learners.

Give A Geeky Valentine!

Reply
Community Manager
Posts: 552

Give A Geeky Valentine!

Just in time for Valentine's Day, delivers code to create a binary message of love for that special someone. Read his blog,

borrow the code and share the love!

Valentines_2015.png

Trusted Advisor
Posts: 1,300

Re: Give A Geeky Valentine!

Your hyperlink for the blog post is missing the semicolon after http

http://blogs.sas.com/content/iml/2015/02/11/binary-heart/

Community Manager
Posts: 552

Re: Give A Geeky Valentine!

Thank you! Fixed now.

Trusted Advisor
Posts: 1,300

Re: Give A Geeky Valentine!

proc fcmp outlib=work.funcs.graph;

   function heartx(t);

      return(16*sin(t)**3);

      endsub;

  

   function hearty(t);

      return(13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t));

      endsub;

     

   run;

  

options cmplib=work.funcs;

proc template;

   define statgraph heart;

      dynamic T;

      begingraph;

         entrytitle " ";

         entryfootnote "{16*sin(t)^3, 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)}, {t, 0, 2*pi}";

         layout overlay / yaxisopts=(

                             label=" "

                             display=none

                             )

                          xaxisopts=(

                             label=" "

                             display=none

                             )

            ;

            entry "Happy Valentines Day";

            if (exists(T))

               seriesplot x=eval(heartx(T)) y=eval(hearty(T));

               endif;

            endlayout;

         endgraph;

      end;

  

   run;

data foo;

   drop pi;

   pi = constant('pi');

   do t=0 to 2*pi by 0.01*pi/4;

      output;

      end;

     

   run;


proc sgrender data=foo template=heart;

   dynamic t="T";

  

   run;

download.png

Community Manager
Posts: 552

Re: Give A Geeky Valentine!

:smileylove:

Trusted Advisor
Posts: 1,300

Re: Give A Geeky Valentine!

How about one or two more...  I don't often need to build graphs, so this has been a fun exercise.

proc fcmp outlib = work.funcs.graphs;

function heart3d(x,y);

      t = 1 - x**2 - (y - abs(x))**2;

      if sign(t)=-1 then return(0);

      return(5-sqrt(t)*cos(30*t));

      endsub;

     

run;

options cmplib=work.funcs;

proc template;

define statgraph heart3d;

      dynamic X Y;

      begingraph;

          layout lattice / rows=1 columns=2;

            layout overlay3d / cube=false rotate=5 tilt=85;

               surfaceplotparm x=X y=Y z=eval(heart3d(X,Y)) /

                  surfacetype = fillgrid;

               endlayout;

               layout overlay;

                   contourplotparm x=X y=Y z=eval(heart3d(X,Y)) /

                  contourtype = fill;

                   endlayout;

               endlayout;

          endgraph;

      end;

     

run;

data ranges / view=ranges;

do x=-1 to 1 by .01;

      do y=-1 to 1.5 by .01;

         output;

         end;

      end;

run;

proc sgrender data=ranges template=heart3d;

dynamic x="x" y="y";

   run;



img0.png

Community Manager
Posts: 552

Re: Give A Geeky Valentine!

These are great! Goes to show...SAS has a heart Smiley Wink

Trusted Advisor
Posts: 1,253

Re: Give A Geeky Valentine!

Including the SAS/Graph guy, Robert Allison's geeky contribution... http://blogs.sas.com/content/sastraining/2015/02/12/have-a-traditional-sasgraph-valentines-day/

valentines_graph.png  valentines_graph1.png

Community Manager
Posts: 552

Re: Give A Geeky Valentine!

Did you know Cupid himself uses SAS? Me either. He's more entrepreneurial than I expected: http://blogs.sas.com/content/sascom/2015/02/11/you-know-what-cupid-loves-money-lots-of-money/

Occasional Contributor
Posts: 16

Re: Give A Geeky Valentine!

Ask a Question
Discussion stats
  • 9 replies
  • 942 views
  • 10 likes
  • 4 in conversation