BookmarkSubscribeRSS Feed
Reeza
Super User

Borrowing from one of the sample codes, here is an animated heart with various colours, a rudimentary attempt at a beating heart 🙂

 

heartbeat.gif

 

*generate data for graph;
data need (drop=t);
    do group=12 to 18 by 0.5;

        do t=0 to 2*constant("pi") by 0.01;
            x=group*sin(t)**3;
            y=13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t);
            output;
        end;
    end;

    do group=18.2 to 12.2 by -0.5;

        do t=0 to 2*constant("pi") by 0.01;
            x=group*sin(t)**3;
            y=13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t);
            output;
        end;
    end;

run;


*macro to create graph for each heart/colour;
%macro create_graph(group=, color=);

proc sgplot data=need noautolegend;
    *title 'Be my valentine';
    where group=&group.;
    scatter y=y x=x / markerattrs=(symbol=squarefilled color=&color.);
    xaxis display=none;
    yaxis display=none;
run;

%mend;



*create animated graph;
options papersize=('5 in', '3 in') printerpath=gif animation=start 
    animduration=0.2 animloop=yes noanimoverlay nonumber nodate;
ods printer file='/home/fkhurshed/heartbeat.gif';
ods graphics / width=5in height=3in imagefmt=GIF;


data list_data;
    set need;
    by group notsorted;
    retain counter;
    
    array colours (0:8) $8 _temporary_ ("CXa6cee3" "CX1f78b4" "CXb2df8a" "CX33a02c" "CXfb9a99" "CXe31a1c" "CXfdbf6f" "CXff7f00" "CXcab2d6");

    
    if first.group then do;
    counter+1;
    selected_colour = colours(mod(counter, 8));
       str=catt('%create_graph(group=', put(group, best12. -l), ', color=', selected_colour, ');');
       call execute(str);
       output;
    end;
run;


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

Explore and visualize your data

 
With a free 14-day SAS® Viya trial, you can:

 

  • Experience all the capabilities of SAS Viya Enterprise, our top-tier Viya offering.
  • Use our pre-loaded data or upload your own (up to 1GB).
  • Access training resources and videos.
  • Add up to four other users so your team can see how Viya works for everyone.
Register Now
Discussion stats
  • 0 replies
  • 551 views
  • 4 likes
  • 1 in conversation