The simple PRINT macro below prints a selected dataset:
%macro print(data=&syslast,obs=5); proc print data=&data(obs=&obs); title "%upcase(&data)"; run; %mend print; |
Suppose you want to print every dataset in the library. Would you enjoy typing a macro call for every dataset in the library?
Only if you enjoy coding in the slow lane!
%print(data=orion.country) %print(data=orion.club_members) %print(data=orion.bizlist) ... |
I don't know about y'all, but, whether I'm driving my Corvette or coding in SAS, I hate the slow lane!
The PRINTLIB macro below puts you in the middle lane by issuing automated data-driven calls to the PRINT macro:
%macro printlib(libname); proc sql noprint; select "&libname.." || memname into :dsn1- from dictionary.tables where libname="%upcase(&libname)"; quit; %do i=1 %to &sqlobs; %print(data=&&dsn&i) %end; %mend printlib; |
While the above macro has power, it suffers from the weight of excessive code; poor power-to-weight ratio!
Would you believe me if I said you could issue identical data-driven macro calls with a 3-line datastep (5 lines if you count the DATA and RUN statements) and no %DO loop? Well, you can! The magic of the EXECUTE routine will put you in the fast lane with a lean mean power-to-weight ratio. Learn all the details, as well as a dangerous pothole to avoid, by attending our tire-squealing new course, SAS Macro Language 2: Advanced Techniques.
photo credit: FastLane_YiLiang, SlowLane_LarsPlougmann // attribution: creative commons