Here's a SAS ODS Graphics take on a cute Valentine's Day craft project for kids. Happy Valentine's Day, all!
* Fun With SAS ODS Graphics: Bee My Valentine
Inspired by Valentine's Day craft projects for kids
https://members.easypeasyandfun.com/downloads/heart-bee-card-for-valentines-day
https://www.etsy.com/listing/1151483398/valentines-day-bee-heart-craft-kit;
data hearts; * Generate parts of the bee;
xT=0.05; yT=2.5; text=')'; output; xT=.; yT=.; * Smile (parenthesis rotated 270 degrees);
x1=0; y1=2.75; y2=4.25; x2=x1-(y2-y1)/3; output; x2=-x2; output; * Antenna (vector lines);
x=x2; y=y2; x1=.; x2=.; y1=.; y2=.; color='YELLOW345'; output; x=-x; color='YELLOW15 '; output; * Tips of antenna (yellow hearts);
y=2; x=-1.25; color='YELLOW90 '; output; y=2; x=1.25; color='YELLOW270'; output; * Wings (yellow hearts);
y=2; x=-1.15; color='BLACK90 '; output; y=2; x=1.15; color='BLACK270'; output; * Wings (black heart overlays);
do y=1.25 to 2.75 by .5; x=0; if color='BLACK ' then color='YELLOW'; else color='BLACK'; output; end; * Body (alternating yellow/black hearts);
data myattrmap; * Bee is made up of MS-Word heart icon images in various colors & sizes (in pixels), rotated at different angles;
input ID $ value : $15. markersymbol : $15. markersize;
datalines;
myid YELLOW heartyellow 267
myid YELLOW15 heartyellow15 50
myid YELLOW90 heartyellow90 267
myid YELLOW270 heartyellow270 267
myid YELLOW345 heartyellow345 50
myid BLACK heartblack 267
myid BLACK90 heartblack90 175
myid BLACK270 heartblack270 175
;
* Generate a bee valentine - vector + scatter + ellipse + text plots;
ods graphics / reset width=5in height=5in antialias border=off imagefmt=svg;
proc sgplot data=hearts noautolegend nowall noborder dattrmap=myattrmap subpixel; * Use discrete attribute map to map objects to their images;
inset 'BEE MINE, VALENTINE!' / textattrs=(color=pappk weight=bold size=20pt) position=top; * Chart title;
symbolimage name=heartyellow image="/home/ted.conway/HeartYellow.png"; * Yellow MS-Word heart icon tilted at various angles;
symbolimage name=heartyellow15 image="/home/ted.conway/HeartYellow.png" / rotate=15;
symbolimage name=heartyellow90 image="/home/ted.conway/HeartYellow.png" / rotate=90;
symbolimage name=heartyellow270 image="/home/ted.conway/HeartYellow.png" / rotate=270;
symbolimage name=heartyellow345 image="/home/ted.conway/HeartYellow.png" / rotate=345;
symbolimage name=heartblack image="/home/ted.conway/HeartBlack.png"; * Black MS-Word heart icon tilted at various angles;
symbolimage name=heartblack90 image="/home/ted.conway/HeartBlack.png" / rotate=90;
symbolimage name=heartblack270 image="/home/ted.conway/HeartBlack.png" / rotate=270;
styleattrs backcolor=cxd41f3a; * "Valentine red" background;
vector x=x2 y=y2 / noarrowheads xorigin=x1 yorigin=y1 lineattrs=(thickness=5pt color=black); * Antenna lines;
scatter x=x y=y / group=color attrid=myid; * Valentine-shaped body and wings;
ellipseparm semimajor=.075 semiminor=.075 / xorigin=.25 yorigin=3 nooutline fill fillattrs=(color=black); * Right eye;
ellipseparm semimajor=.075 semiminor=.075 / xorigin=-.25 yorigin=3 nooutline fill fillattrs=(color=black); * Left eye;
text x=xT y=yT text=text / contributeoffsets=none rotate=270 textattrs=(weight=bold size=48pt) strip; * Mouth (rotated parenthesis);
xaxis display=none values=(-2.5 2.5) offsetmin=0.03 offsetmax=.03; * Suppress axes and limit bounds of chart;
yaxis display=none values=(0 5) offsetmin=0.03 offsetmax=.03;
MS-WORD HEART ICONS USED (RESIZED & ROTATED IN SAS CODE)
You could use Heart function from @Rick_SAS blog:
https://blogs.sas.com/content/iml/2011/02/14/a-parametric-view-of-love.html
And rotate matrix from @GraphGuy blog:
https://blogs.sas.com/content/graphicallyspeaking/2021/07/14/sas-can-turn-your-world-upside-down/
https://matthew-brett.github.io/teaching/rotation_2d.html
to fetch these rotate heart shape.
data have1;
Pi = constant("Pi");
do t=0 to 2*Pi by 0.01*Pi/4 ;
r = 2 - 2*sin(t) + sin(t)*sqrt(abs(cos(t))) / (sin(t)+1.4);
/** Convert to Euclidean coordinates for plotting **/
x = r*cos(t);
y = r*sin(t);
output;
end;
run;
%let angle=90;
data have2;
set have1(rename=(x=_x y=_y));
angle_radians=&angle*(constant("pi")/180);
x=cos(angle_radians)*_x - sin(angle_radians)*_y;
y=sin(angle_radians)*_x + cos(angle_radians)*_y;
drop _x _y angle_radians;
run;
%let angle=180;
data have3;
set have1(rename=(x=_x y=_y));
angle_radians=&angle*(constant("pi")/180);
x=cos(angle_radians)*_x - sin(angle_radians)*_y;
y=sin(angle_radians)*_x + cos(angle_radians)*_y;
drop _x _y angle_radians;
run;
%let angle=270;
data have4;
set have1(rename=(x=_x y=_y));
angle_radians=&angle*(constant("pi")/180);
x=cos(angle_radians)*_x - sin(angle_radians)*_y;
y=sin(angle_radians)*_x + cos(angle_radians)*_y;
drop _x _y angle_radians;
run;
data want;
set have1-have4 indsname=dsn;
group=dsn;
run;
proc sgplot data=want aspect=1;
series x=x y=y/group=group;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.