I use SAS fairly regularly in my job. I’ve taken a number of SAS programming courses, yet I don’t get to use much of what I’ve learned because the manner in which I use SAS is fairly basic. (A lot of SAS courses seem to use examples that don’t really relate to my work, such as business processes, evaluating credit scores and so on. I do a lot of statistical analysis of survey microdata.)
In a program I’m enhancing, I want to execute some code in another SAS program based on whether a certain variable is set to a certain value. In most languages, such as Perl or C, you would put this in an if-then-else construct and you’d be done. Because of the procedural nature of SAS, with data steps and macros, it’s not that straightforward.
I did some googling on the basis that I can’t possibly be the only person wanting to do this (it turns out I’m not) and found a thread on this very topic in the SAS Support Community forums. Wading through the responses, I found a several different ways people suggested doing it; some people who couldn’t possibly envision why you’d want to do it; a couple who got hung up on the content of the programs that the original poster wanted to conditionally execute; and one answer that stood out from all the others in terms of its simplicity, which I’ve included almost verbatim below, with some comments for clarity. (more…)