A SAS Christmas tree

A few colleagues and I were exchanging short snippets of SAS code that create Christmas trees and other holiday items by using the SAS DATA step to arrange ASCII characters. For example, the following DATA step (contributed by Udo Sglavo) creates a Christmas tree with ornaments and lights:

data _null_;
put @11 '@';
do i=0 to 9;
  put @(11-i) b;
put @10 '| |';
         | |

If you delete some unnecessary spaces, you can produce the Christmas tree in 90 characters. As a result, the DATA step is short enough to post on Twitter! So tweet the following message to all of your SAS friends!

#SAS XMas Tree http://bit.ly/uQELwe  
DATA;put@9'@';do i=0 to 8;b=substr(repeat('*0',i),1,2*i+1);put@(9-i)b;end;
put@8'| |';RUN;

Can you do better? One of my colleagues create a 76-character DATA step that produces a plain Christmas (with a star (*) on top) made entirely of the '0' character. Use the comments to post your favorite SAS code that spreads holiday cheer!

tags: Just for Fun, SAS Programming


  1. StateWorker
    Posted December 16, 2011 at 9:10 am | Permalink

    This is so much fun!!!!

  2. Posted December 16, 2011 at 12:26 pm | Permalink

    Cool! I like the light bulb on the top.

  3. FriedEgg
    Posted December 16, 2011 at 12:35 pm | Permalink

    You do not want to forget Hanukkah

    data _null_;
    put #1 @9 '(' #2 @1 '(' @9 '|';
    do i=' ','_';
    do k=1 to 17;
    c=ifc(not mod(k,2),i,'|');
    put #j @k c @;
    put #j @8 '_|_';

    (       |
    | | | | | | | | |

  4. sanjeev
    Posted December 22, 2011 at 11:48 am | Permalink

    wow, great skill.....

  5. Posted December 17, 2012 at 2:52 pm | Permalink

    Bolotin Yevgeniy pointed out that you can get under 90 characters if you replace SUBSTR with ||:

    DATA;put@9'@'/@9'*';do i=0to
    7;b='*'||repeat('0*',i);put@(8-i)b;end;put@8'| |';RUN;

  6. Joseph Hinson
    Posted December 20, 2016 at 10:43 pm | Permalink

    Really cool. Would be nice if you could randomly iterate with @ replaced by blanks to simulate blinking lights.

One Trackback

  1. [...] using different parameter values. Last year during the holiday season I published some attempts to construct a Christmas tree by using the SAS DATA step. It was fun to see contributions from many SAS programmers, including a menorah! This year I issue [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>