SAS author's tip: Structured thinking about writing programs

0

Statistical Programming in SASThis week's SAS tip is from A. John Bailer and his book Statistical Programming in SAS. A SAS user for over 30 years, John is a Fellow of the American Statistical Association and the Society for Risk Analysis--and a member of the International Biometric Society and the International Statistical Institute.

The following excerpt is from SAS Press author John Bailer and his book "Statistical Programming in SAS" Copyright © 2010, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software).

Structured Thinking about Writing Programs

Homework problems are frequently simple, and if a computer program is required for analysis, then this program might need only a few lines of code to implement a solution. These small programs can be written on the fly without a great deal of planning. This strategy of short and quick program construction fails miserably when you are faced with larger problems and when alternative solutions are required. A basic strategy is advocated in this case: modularize your code and write pseudocode that is operationalized as functioning programming statements during implementation. This strategy is outlined in this section and illustrated in the case studies that follow.

Modular programming is commonly introduced in computer science when basic programming skills are taught. The basic idea is a simple one—when faced with a large and complex task, subdivide this task into smaller components. These smaller components can be implemented and tested before they are combined in a larger program. Often, these components are separate modules that can be implemented as subroutines or functions. However, these components might represent discrete ideas that need to be implemented with a module as well. Variants of these subroutines or functions are encountered in SAS macro programs (in Chapter 10) or in SAS/IML modules (in Chapter 11).

Pseudocoding involves writing in words or sentence fragments what should occur in a large programming task. In decades past, programming students learned about structured programming ideas with extensive discussions and formal flowcharts about how a program should work. This formal flowchart of the overall program execution might be further expanded into components or modules of an even larger program that could be described in additional formal flowcharts. All of this seems to be a lost skill with many of the students of today (as is the speedy use of slide rules). Pseudocode provides a way to expand tasks into modular pieces with textual descriptions of what these pieces do. The abstract descriptions in discussions and flowcharts don’t provide a real sense of how the code might work in practice.

To read a free chapter and reviews of the book, visit John's author page. View 4 previously excerpts from his book on this blog: Selecting a simple random sample,  Using PROC PRINT to list observations in a data set, PROC MEANS for descriptive statistics, and Destination--RTF, HTML, PDF, and more.

Share

About Author

Shelly Goodin

Social Media Specialist, SAS Publications

Shelly Goodin is SAS Publications' social media marketer and the editor of "SAS Publishing News". She’s worked in the publishing industry for over thirteen years, including seven years at SAS, and enjoys creating opportunities for fans of SAS and JMP software to get to know SAS Publications' many offerings and authors.

Comments are closed.

Back to Top