From the course: SAS Programming for R Users, Part 2

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Macro programming

Macro programming

- [Instructor] In this section, I'll show you how to create a macro program. We'll use macro programs to run SAS code repetitively and we can also run SAS data and PROC steps conditionally or iteratively. You can think of a macro program simply as an R function to provide what ever customization you want. For example, I want to create a macro program called randnorm, where I pass at a single parameter, simply the number of observations I'm going to simulate from a normal distribution. Then, I'll use that data set to generate some reports. For example, I want a table and graphic. We'll do all of this inside of a single program. So an R randnorm would look something like this, I have the function, my single argument, n, I would generate data with the rnorm function, call it vec. I could print some summary statistics and then I can go ahead and create plots based on that data. But, of course, once you type this up once, you can use the function and pass at whatever parameter you want…

Contents