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!


About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.


  1. 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 '_|_';

    (       |
    | | | | | | | | |

  2. Pingback: Iterated function systems and Barnsley’s fern in SAS - The DO Loop

  3. 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;

Leave A Reply

Back to Top