The Best of Cheesy, SleazSAS Tricksy SAS Tricks
The Best of Cheesy, SleazSAS Tricksy SAS Tricks
The Best of Cheesy, SleazSAS Tricksy SAS Tricks
ABSTRACT
Based on an off-hand comment, the author solicited examples of cheesy or sleazy SAS tricks from his friends on the SAS-L distribution list. To qualify, the trick might be a coding declaration or other construction that suppresses the over-solicitous manner in which SAS tries to protect coders from themselves. A trick might also qualify if it hinted at an unexpected SAS behavior that works against coding stereotypes. The following paper presents some of the best tricks received.
ERR-OR, WARN-ING
Whenever I see ERROR or WARNING in a SAS Log, a small shiver travels along my spine. Many SAS users (and their bosses) feel the same sense of trepidation when they see these two words in a SAS Log. So for custom control messages in a program, Christoph Edel uses the following trick: data _null_ ; put "WARN" "ING: - bad thing! Check!" _all_ ; run ; By splitting the WARNING or ERROR between two literal strings, these tokens do not appear in the SAS Log unless the trigger condition emerges. Notice that no concatenation operator is needed between the two literal strings.
value myfmt 1=" High School" 2="College" 3="Grad School" ; In the FREQ procedure, format labels with a leading blank sort ahead of the other values but the blanks do not appear in the report.
pointer is held, we can have our way with _infile_ as this trick illustrates.
To see the value of a variable in the compute block, insert the following code: call execute('%put' || <variable>) ; This trick qualifies as cheesy and sleazy since one would expect the CALL EXECUTE to reference a macro, not a %PUT.
CONCLUSION
As the following tricks illustrate, SAS can be a subtle language. The following tricks only scratch the surface of these features and how to exploit them. An implication of cheesy and sleazy is that one might fear that some of these tricks stop working in subsequent SAS releases. However, in the authors opinion, these features are well embedded in SAS and will probably continue to be available in subsequent releases and across platforms. The author may revisit this subject in the future. So feel free to submit your candidates for cheesy, sleazy tricks to the author at the email address shown below.
ACKNOWLEDGMENTS
SAS is a registered trademark of the SAS Institute, Inc. of Cary, North Carolina. The author wishes to thank his SAS-L friends who contributed cheesy, sleazy tricks used in this paper. He also would like to thank Ralph Leighton, who suggested the idea for this paper.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author at: Michael L. Davis Bassett Consulting Services, Inc. 10 Pleasant Drive North Haven CT 06473-3712 Phone: 203-562-0640 Fax: 203-498-1414 Email: michael@bassettconsulting.com Web: http://www.bassettconsulting.com