BookmarkSubscribeRSS Feed
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

otextscatterplotxmastree.png

 

A SAS ODS Graphics text/scatter plot take on a couple of neat word search-themed architect and designer Xmas cards at dezeen. Happy Holidays, all!

 

* Fun With SAS ODS Graphics - O [Text & Scatter Plot] Xmas Tree
  A take on a couple of holiday cards at dezeen.com/2022/12/23/christmas-cards-architects-designers-2022/;

data letters(keep=r c letter randnum);        * Generate random A-Z letters to fill a 13x13 grid;
retain a2z 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letter ' ';
do r=1 to 13;
  do c=1 to 13;
    randnum=1+floor(rand("Uniform", 26));
    letter=substr(a2z,randnum,1);
    output;
  end;
end;  

data message(keep=x0 y0 xM yM textM);          * Generate x/y points and letters for a "Happy Holidays!" message; 
retain textM ' ';
msg=" HAPPYHOLIDAYS!";                         * Holiday message, x/y offset points for where to display letters (leave space at top for star!);
msgXY="0,0 -1,-2 1,-2 -2,-4 0,-4 2,-4 -3,-6 -1,-6 1,-6 3,-6 -4,-8 -2,-8 0,-8 2,-8 4,-8";
x0=7; y0=11;                                   * x/y origin of top of "Xmas tree";
do i=1 to length(msg);                         * Calc x/y locations of message letters;
  textM=substr(msg,i,1);                       * Message letter;
  xM=x0+scan(scan(msgXY,i,' '),1,', ');        * x location of message letter (origin+offset);
  yM=y0+scan(scan(msgXY,i,' '),2,', ');        * y location of message letter (origin+offset);
  output;
end;

proc sql;                                      * Insert our message into the grid, set color to white for message letters, black for others;
create table lettersmessage as 
select l.r, l.c, case when m.xM is null then 0 else 1 end as color, case when m.xM is not null then m.textM else l.letter end as letter, m.xM, m.yM, m.x0, m.y0
from letters l left join message m on l.r=m.yM and l.c=m.xM;
                                               * Display the tree!;
ods graphics / reset=all width=6.5in height=6.5in imagefmt=svg noborder;
proc sgplot data=lettersmessage noborder nowall noautolegend pad=0 aspect=1;
styleattrs backcolor=cx008975;                 * Nice shade of green from card (hex RGB code obtained using Paintbrush eyedropper);
text x=c y=r text=letter / colorresponse=color textattrs=(size=16pt weight=bold) colormodel=(black white); * Display black & white letters;
scatter x=x0 y=y0 / markerattrs=(size=11pt color=white symbol=starfilled); * Put a star on top;
scatter x=xM y=yM / markerattrs=(symbol=circle size=26pt color=white); * Draw white circles around message letters and star;
xaxis display=none values=(0 to 14); yaxis display=none values=(0 to 14); * Suppress axes and set width/height bounds;
run;
1 REPLY 1
RichardAD
Quartz | Level 8

Don't ignore rereading the RAND documentation...

letter=substr(a2z,rand('integer',1,26),1);

or ASCII

letter = byte(64+rand('integer',1,26))

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 3053 views
  • 6 likes
  • 2 in conversation