Sunday is Easter, so here's a SAS ODS Graphics take on a delicious-looking Easter egg cookie. Happy Easter, all!
* Fun With SAS ODS Graphics: Easter Egg Cookie (Polygon + Vector + Scatter + Spline Plots)
Inspired by delicious-looking cookie pictured at chicagofoodmagazine.com/news/easter-2025;
data points; * Create points for Easter Egg Cookie made from an ellipse and a circle;
poly=1; * One polygon of points;
do x=-.75, -.75 to .75 by .01, .75; * Top is a vertical half-ellipse (width=.75, height=1);
y=sqrt(1-x**2/.75**2);
if y^=. then output; * Polygons don't like missing values, kids!;
end;
do x=.75, .75 to -.75 by -.01, -.75; * Bottom is a semi-circle (r=.75, generate points right to left for polygon);
y=-sqrt(.75**2-x**2);
if y^=. then output; * Polygons don't like missing values, kids!;
end;
x=.; y=.; * Done with polygons;
do vy=.15, .45, .75; * Draw 3 'frosting' lines using vectors;
vx1=-.75*sqrt(1-vy**2)+.075;
vx2=-vx1;
vcolor=(vy=.75); * Make top line yellow (1), others white (0);
if vx1^=. and vx2^=. then output;
end;
vx1=.; vx2=.; vy=.; * Done with vectors;
dots=5; * Scatter plot of 16 frosting dots group in 2 groups of 2 lines of staggeed points (1st line has 5 points);
scolor=0; * Bottom group of dots will be white;
do wy=.15, .45; * Calc y value for each group of lines;
l=-.75*sqrt(1-(wy+.1)**2)+.15; * Calc left starting point (x);
do i=0 to dots-1; * Print each row of dots (four lines of 5, 4, 4, 3 dots in each);
sx=l+i*abs(l)*2/(dots-1); sy=wy+.1; output; * Calc x value of point for bottom line;
if i<=(dots-2) then do; * Stagger x values for top line of each group and recalc y value;
sx=l+i*abs(l)*2/(dots-1)+.5*abs(l)*2/(dots-1); sy=wy+.2; output; end;
end;
dots=dots-1; * Top group of dots will contain one less dot than bottom group;
scolor=1; * Top group of dots will be yellow;
end;
sx=.; sy=.; * Done with frosting scatter plot points;
do s2y=.01 to -.72 by -.65/25; * Generate x/y points for candy sprinkles covering bottom semi-circle of cookie;
xl=-sqrt(.75**2-s2y**2)+.025; * Compute how much space we have to work with for each line;
xr=-xl;
n=floor(abs(xl-xr)/(.65/25)); * "Nudge" lines over to right so each row is centered;
nudge=(abs(xl-xr)-n*(.65/25))/2;
do s2x=xl+nudge to xr by .65/25; * Fill each row with sprinkles;
s2color=rand("Integer", 0, 4); * Assign colors (0-4 = white red yellow blue green);
if s2x^=. then output;
end;
end;
* Hard work is done, let's 'bake' a cookie (Polygon/Vector/Scatter/Spline plots);
ods graphics / reset antialias border=off height=5in width=5in imagefmt=svg;
proc sgplot data=points aspect=1 noborder noautolegend nowall; * Generate Easter Egg - polygon plot of half-ellipse + semi-circle points, spline plot border, text plot message;
styleattrs backcolor=cxDDE4F4; * Pastel background;
polygon x=x y=y id=poly / nooutline fill nooutline fillattrs=(color=cxF2DBDD transparency=0); * Eather Egg Cookie;
vector x=vx2 y=vy / xorigin=vx1 yorigin=vy noarrowheads lineattrs=(color=white thickness=6pt) colormodel=(white yellow) colorresponse=vcolor; * Frosting lines;
scatter x=sx y=sy / markerattrs=(symbol=circlefilled color=white size=16pt) colormodel=(white yellow) colorresponse=scolor; * Frosting dots;
scatter x=s2x y=s2y / markerattrs=(symbol=circlefilled color=white size=5.25pt) colormodel=(white red yellow blue green) colorresponse=s2color; * Candy sprinkles;
spline x=x y=y / lineattrs=(color=pink thickness=3pt); * Draw smoother outline of Easter Egg;
xaxis display=none min=-.925 max=.925 offsetmax=.001 offsetmin=.001; * Limit x/y axis bounds;
yaxis display=none min=-.80 max=1.05 offsetmax=.001 offsetmin=.001;
run;
TASTIER VERSION OF ABOVE
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.