BookmarkSubscribeRSS Feed
stephenB
Fluorite | Level 6

Hello,

I am discovering the Valentine's Day DataViz Challenge, which seems to take place every year and ends in 1 day. I am not an expert in SAS Graph and its new features, so I have created this first version, which I will strive to improve for future challenges.

I have been inspired by various tips and tricks, including those presented in the programs by Michelle Homes, Rick Wincling, and @tc's, to quickly create this visualization.

This SAS program generates a series of heart-shaped curves and animates them with different colors. It also includes additional text annotations. The resulting graph is my first Valentine's Day-themed visualization.

 

%let pink = cxFF3333; /* Define the color variable for pink */

%let textcolor = &pink.; /* Allow to Define a different color for text if needed */

%let pas = 2; /* Step size */
%let lower = 20; /* Lower limit */
%let upper = 98; /* Upper limit */

data heart_data1;
do x = -2 to 2 by .005;
y = sqrt(1 - (abs(x) - 1) ** 2);
output;
end;
do x = 2 to -2 by -.005;
y = arcos(1 - abs(x)) - 3.14;
output;
end;
run;

data textOnly;
retain tx 0 ty -0.2 msg "HAPPY/VALENTINE'S/DAY/2024"; /* Define the text and its position !! "By hand" at the moment */
run;

%macro echelle(i = &lower., j = &upper., tick = &pas.);
%do k = &i. %to &j. %by &tick.;
data heart_data&k.;
set heart_data1;
x&k. = x * %sysevalf(&k./100.);
y&k. = y * %sysevalf(&k./100.);
drop x y;
run;
%end;
%mend;

%echelle /* Generate multiple datasets with scaled data */

run;

%macro fustout(i = &lower., j = &upper., tick = &pas.);
%global var;
%let var = heart_data&i.;
%do k = %eval(&i. + &tick.) %to &j. %by &tick.;
%let var = &var heart_data&k.;
%end;
%put &var.=;
%mend fustout;

%fustout /* Concatenate dataset names into a global macro variable */

run;

*%put &var =; /* Display the concatenated dataset names */

*run;

data heart_datafin;
merge heart_data1 &var. textonly; /* Merge the scaled datasets, original dataset, and text dataset */
run;

%macro plotplusieurs(i = &lower., j = &upper., tick = -&pas.);
%do k = &j. %to &i. %by &tick;
series x = x&k. y = y&k. / lineattrs = (color = cxFF%eval(3333 + &k.) thickness = 2); /* Plot multiple series with different colors */
%end;
%mend plotplusieurs;

Title "Valentine’s Day Data Viz Challenge"; /* Set the title of the graph */

footnote "stephen version 1 on &sysdate."; /* Set the footnote */

footnote2 "to be continued"; /* Set another footnote */

proc sgplot data = heart_datafin noautolegend; /* Start the SGPLOT procedure with the merged dataset */
series x = x y = y / lineattrs = (color = &pink thickness = 2); /* Plot the main series */
%plotplusieurs /* Plot additional series */
text x = tx y = ty text = msg / textattrs = (color = &textcolor size = 5pt) splitchar = '/' splitpolicy = splitalways contributeoffsets = none; /* Add text with specified attributes */
run;

1 REPLY 1
MichelleHomes
Meteorite | Level 14

Excellent work @stephenB! 😍

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

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