SAS Jedi Christmas - SAS 9.4 M4 DS2 Do Loop Upgrade

6

This SAS Jedi is very excited about the SAS 9.4 M4 release, which brought many wonderful gifts just in time for Christmas. So in the interest of extending the Christmas spirit, I'm going to blog about some of my favorites!

I've long loved the SAS DO statement variant which allows iterating over a discrete list of values:

data test;
   call streaminit(12345);
   do Month='Jan','Feb','Mar';
      Revenue = round(rand('NORMAL',1000,100));
      output;
   end;
   format Revenue dollar8.;
run;


Until now, this has only been available in the traditional SAS DATA step. Neither DS2 nor SAS Macro had this feature. And every time I teach the DS2 class, I've had to say it wasn't available in DS2, but was on my wish list. Well, with the M4 release of SAS, I don't have to wish anymore! :-)

proc ds2;
title 'DS2 Results';
data;
   dcl char Month;
   dcl int Revenue having format dollar8.;
   method init();
      streaminit(12345);
      do Month='Jan','Feb','Mar';
         Revenue = round(rand('NORMAL',1000,100));
         output;
      end;
   end;
enddata;
run;
quit;

jedi20161228_ds2_data_program

So Merry Christmas from SAS! As usual, you can download the code for this episode from HERE.

And may the SAS be with you in the New Year!
Mark

Share

About Author

SAS Jedi

Principal Technical Training Consultant

Mark Jordan (a.k.a. SAS Jedi) grew up in northeast Brazil as the son of Baptist missionaries. He served 20 years as a US Navy submariner, pursuing his passion for programming as a hobby. Upon retiring from the Navy in 1994, he turned his hobby into a dream job and has been a SAS programmer ever since. Mark writes and teaches a broad spectrum of SAS Foundation programming classes, and is proud to announce his first book, "Mastering the SAS® DS2 Procedure: Advanced Data Wrangling Techniques". When he isn’t writing, teaching, or posting “Jedi SAS Tricks” here on the SAS Learning Post, Mark enjoys playing with his grand and great-grandchildren, hanging out at the beach and reading science fiction novels. His secret obsession is flying toys – kites, rockets, drones – and though he usually tries to convince Lori that they are for the grandkids, she isn't buying it. Mark lives in Toano, VA with his wife, Lori, and their cat, the amazing Tiger Man. To connect with Mark, check out his SAS Press Author page, follow him on Twitter @SASJedi or connect on Facebook or LinkedIn.

Related Posts

6 Comments

  1. Very cool!

    One of my personal favorites in M4 is the accessibility option for ODS HTML5 and PDF - such a HUGE timesaver for all of us submitting reports and files to government agencies!

    Thanks for sharing.

    • SAS Jedi

      I was especially excited about this one because it was an answer to a request by several customers and me, too. However, the ODS features are also amazing - stand by for more blogging :-)
      Mark

  2. What did I do wrong? I got this error, ERROR: Compilation error

    127 proc ds2;
    128 title 'DS2 Results';
    129 data;
    130 dcl char Month;
    131 dcl int Revenue having format dollar8.;
    132 method init();
    133 streaminit(12345);
    134 do Month='Jan','Feb','Mar';
    135 Revenue = round(rand('NORMAL',1000,100));
    136 output;
    137 end;
    138 end;
    139 enddata;
    140 run;
    ERROR: Compilation error.
    ERROR: Parse error. Expecting TO on source line 134: streaminit(12345); do Month='Jan' ==>,.
    141 quit;

    NOTE: PROCEDURE DS2 used (Total process time):
    real time 0.04 seconds
    cpu time 0.04 seconds

    • SAS Jedi

      Mike,
      Are you using the latest (November 2016) release of SAS (SAS 9.4 M4)? This blog is about new features in the new release, so you'll need the latest release to make this work. If you don't already have the latest version of SAS, that's OK - the SAS University Edition is free to download, and is always up to date! You can get it from http://go.sas.com/free_sas.
      May the SAS be with you!
      Mark

Leave A Reply

Back to Top