Download presentation
Presentation is loading. Please wait.
Published byArleen Shaw Modified over 6 years ago
1
Automate Repetitive Programming Tasks: Effective SAS® Code Generators
Copyright © 2010, SAS Institute Inc. All rights reserved. Yun (Julie) Zhuo, Axio Research LLC SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are trademarks of their respective companies.
2
Automate Repetitive Programming Tasks: Effective SAS® Code Generators
2/25/2019 Automate Repetitive Programming Tasks: Effective SAS® Code Generators Yun (Julie) Zhuo, Axio Research LLC Introduction The Macro-Variable Technique Conclusion The technique interacts with a driver SAS data set to generate SAS codes from variables in the driver data set. It stores the SAS codes using a macro variable, then resolves the macro variable inside SAS statements. The process flow is demonstrated below. SAS programmers often need to perform computing chores that require a lot of repetitive typing. Manual coding is tedious and inefficient, and it almost inevitably introduces human errors that compromise quality. This paper introduces the code-generating approach and demonstrates two techniques. In this paper, we demonstrate that automatic SAS code generators are reliable and efficient methods for repetitive programming tasks. The code-generating approach has served us well. It has the potential of eliminating repetitive programming chores for SAS programmers. For the codes and the demonstration of the technique, enter here: DEMO The CALL EXECUTE Technique The CALL EXECUTE routine interacts with a driver SAS data set, building SAS codes dynamically as data step iterates, making it an effective SAS code generator. The process flow is demonstrated below. Techniques Reference Code-generating techniques in SAS include the following: • Create and resolve a macro variable • Call Execute routine • Put statements that write codes to an associated file • Batkhan, L “SAS Blogs: CALL EXECUTE Made Easy for Data-Driven Programming.” Accessed July 26, 2018. • Shan, X “Transpose Dataset by MERGE.” Proceedings of the SAS Global Forum 2015, Cary, NC: SAS Institute Inc. For the codes and the demonstration of the technique, enter here: Slide 3 Comparison Both techniques require similar amount of coding. The macro variable technique is subject to the limitation that the length of macro variables cannot exceed 65,534 characters. The Call Execute technique is inherent more efficient, although it may need longer run time in order to write generated codes to the log window synchronously when it runs in the interactive mode. Table 1 compares real run time (seconds) from 20 runs to generate 100 variable labels. Mode Technique Mean SD Min Max Batch Macro Variable 0.025 0.008 0.015 0.032 Call Execute 0.013 0.007 0.000 0.016 Interactive 0.087 0.017 0.062 0.110 0.197 0.031 0.144 0.235 Examples Contact Info Two techniques will be demonstrated with two examples: • Automate variable label creation • Reshape data set from vertical to horizontal. Yun (Julie) Zhuo Axio Research LLC Table 1. Real Run-Time Statistics (Seconds)
3
The Macro-Variable Technique (Continued)
2/25/2019 Automate Repetitive Programming Tasks: Effective SAS® Code Generators Yun (Julie) Zhuo, Axio Research LLC The Macro-Variable Technique (Continued) Example 1: Automate Variable Label Creation Example 2: Transpose Variables
4
The CALL EXECUTE Technique (Continued)
2/25/2019 Automate Repetitive Programming Tasks: Effective SAS® Code Generators Yun (Julie) Zhuo, Axio Research LLC The CALL EXECUTE Technique (Continued) Example 1: Automate Variable Label Creation Example 2: Transpose Variables
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.