SAS tip: Why you always should use a RUN statement

By , July 18, 2010 5:23 pm

OK, there are lots of places where it’s written that using RUN statements makes code look cleaner, but that invocation of another PROC statement makes the previous PROC get submitted. So…. It sounds like that RUN statement is a sort of esthetic extra.

But it can bite you

Try something like this
title 'title 1';
proc print data = data1;
title 'title 2';
proc print data = data2;
title 'title 3';
proc print data = data3;
run;

You’d think that the title2 statements would match with the data. But they don’t; rather, the title2 for data1 is ‘Subtitle2′ and so on. If you put a RUN before each PROC then you will get what you want. But if your data1, data2 and data3 are similar, it can be hard to spot this. And I don’t find it intuitive at all.

So …. Always use RUN.

4 Responses to “SAS tip: Why you always should use a RUN statement”

  1. Rick Wicklin says:

    Great tip. The more complete tip might be “Always use RUN or QUIT.”

    In PROC IML, the RUN statement is used to execute modules, so do not use a RUN statement at the end of an IML program.

    In general, for interactive procs (such as REG) the RUN statement executes previous statements but does not exit the PROC. It is not until you execute QUIT that output is produced, files are closed, and so forth.

  2. Peter Flom says:

    Hi Rick
    Thanks! I’ve not used PROC IML, but I have run (!) into the run vs. quit problem on PROC REG.

  3. Rick Wicklin says:

    For a taste of IML, you can download my 2010 SAS Global Forum paper:
    http://support.sas.com/rnd/app/papers/papers_iml.html

    If you like what you see, you might consider a new forthcoming book on IML:
    http://support.sas.com/publishing/authors/wicklin.html

  4. Hi Peter, I just noticed your nice blog when I was out on Rick Wicklin’s blog today. I was wondering if you were interested in nominating your blog for the sasCommunity.org Planet located here: http://www.sascommunity.org/planet/. You can submit your request in the right nav.

Leave a Reply