A time-saving coding tip: leverage the SAS macro facility

3

Hi!  My name is Jim.  I’m a SAS instructor based in Irvine, CA.  I spend a lot of time each year teaching students in CA and across the United States how to program in SAS and how to master the SAS macro facility.

In case you haven’t taken one of our  SAS macro language courses yet, I want to share this tip. The SAS macro language will not make your computer or SAS run faster.   However, if your job includes writing SAS code, the macro language can make you faster.  For example, consider this simple SAS program:

proc print data=orion.customer (obs=8);
      title "Customer List";
      footnote "Created 10:24 Monday, 14FEB2012";
run;
The poor SAS user who uses the above program has to manually type the time, day, and date.  Worse, what if this same user wants to run the same or similar program repeatedly at different times?  What a nightmare -- this poor user must retype the time, day, and date again and again, and try not to make any mistakes!

Fortunately, there's an easier way.  The answer:  automatic macro variables! Note the references to three automatic macro variables in the footnote statement within the SAS program below:

proc print data=orion.customer;
      title "Customer List";
      footnote "Created &systime &sysday, &sysdate9";
run;

When you use the code above, you only have to type the macro variable references once.   You’ll never type them again!   The footnote will always reflect the correct time, date, and day.   Be sure to use double-quotes, not single quotes, on the FOOTNOTE statement!  One caution:  The time, date, and day reflect the moment our SAS user launched his or her interactive SAS session; not the moment that he or she submitted the program.

To learn how to force automatic time, date and day updates and apply desired formats, consider attending our SAS Macro Language 1: Essentials course.  What do you have to lose?  Only time.

Tags SAS macro
Share

About Author

Jim Simon

Principal Technical Training Consultant

Jim Simon is a principal instructor and course developer for SAS Education. Jim has a bachelor's degree from UCLA and a master's degree from California State University at Northridge. Prior to joining the SAS Irvine office in 1988, Jim was an instructor at Ventura College and a SAS programmer at The Medstat Group in Santa Barbara. Jim's areas of specialization include the DATA step, application development, web enablement, and the SAS macro language. A native of Southern California, Jim enjoys anything in the warm California sun. On weekends, Jim loves jumping in his Corvette, turning up the stereo, and cruising Pacific Coast Highway, top down, South to Laguna Beach or North to his old home town, Santa Barbara.

3 Comments

  1. Divyesh Dave on

    I know you mentioned that we have to use double quotes on the FOOTNOTE statement since
    it uses macro variables. I would like to explicitly mention that double quotes are always needed whenever macro variables are used.

Back to Top