 Hi there, thank you for joining me, Monica Wahee, as we promenade towards knowledge with respect to SAS On Demand for Academics, otherwise known as SAS ODA. In this video, I'm going to show you how to make it so a SAS macro can take parameter input when you launch it. Okay, here we are in the SAS On Demand for Academics, or SAS ODA environment. If you need help setting up your free account in SAS ODA, you can take my free online course called Getting Started with SAS ODA. I clue you into the backstory on SAS. I'll link you to it in the description. Okay, so assuming you got started with SAS ODA, you now know how to open our program window and copy and paste code into it. So please go to GitHub and get this code, open a program window, and paste the code in. Alright, as you can see, I have two sets of code in the program window, a top set and a bottom set. I'm not really going to talk about the top set, except to say that this is the code that we built and ran in my video, building a simple macro in SAS ODA. The reason I called it simple is that it didn't take any parameters. So you can see from this top code I showed in another video, I built the macro, but each time you run the macro, all the parameters are the same. See here where we launch the macro? We don't set any parameters when we launch it. See here? This is where our macro variable selected underscore state is set up, and we set it to 12. Oh, just to make sure you know, we are using data from the Behavioral Risk Factor Surveillance System, or BRFSS. This is an annual health survey done by phone in the US. So of course they keep track of what state each respondent is in. So I created this exercise data set from the BRFSS data that just has three states in it, and Florida is the state that has the code 12. So this macro is not very flexible in that it sets a macro variable called selected underscore state equal to 12, then just runs a macro on records where selected underscore state equals 12. So if you launch this macro, it's kind of a one-trick pony. It just runs for state equals 12, which is Florida, and you can't get it to run for any other state. But that's state underscore freak 1. Down here, we are revising the code to allow it to take in different parameters when we launch the macro. So notice how we named the macro a different name. This one is called state underscore freak 2. Notice this change. When we declare the macro command in the second code, we now add selected underscore state equals in parentheses. This is what tells SAS to get outside input so the macro variable can be set before the macro runs by whoever or whatever is launching the macro. But also, notice that when you do this, you make it so you don't really need a let statement anymore. Because the let statement set the value of the macro variable, and now you're just going to do that when you launch the macro. So the let statement is not in the second macro. The one we are calling state underscore freak 2. Okay, since we went over the differences between state underscore freak 1 and state underscore freak 2, now let's run state underscore freak 2 and put it in memory. So we'll highlight the code from macro to mend and run. Okay, well, as we expected, we get no real feedback from SAS and the log file about the macro. We won't get any feedback until we actually launch it. So let's go back to our code and launch it. Okay, now here is another difference from the macro state underscore freak 1. Notice how when we launch the macro, we now need to include a value for selected underscore state in parentheses after it, or the code won't run. So now that we redid the macro this way, it requires input to set selected underscore state to some value. So we just set the selected state to be 12, like it was with state underscore freak 1, just to make sure the macro actually runs after we make this change. We can compare the output between state underscore freak 1 and state underscore freak 2 because they should be the same. So let's highlight this line of code where we launch our new state underscore freak 2 macro and run it. All right, I'm not sure if you remember, but we included the value of selected underscore state in the title. And we see here that it evaluated to 12 and also we recognize these numbers from the output we got when we launched the macro state underscore freak 1. So things look good. Now let's try a test. Let's go back to our code. Remember how I said I included three states in this data set? States numbered 12, 25, and 27? Well, let's see what happens if we change this 12 to a 25 when we launch this macro and see if SAS notices. Let's edit this and run it. See, look at that. SAS noticed that we changed the parameter to 25. And we can tell by looking at the title and also the numbers match the ones for state equals 25. And of course, we could look in the log file to be extra sure. But this is the deal for when you want to set up your macro so you can parameterize it on the fly when you launch it. If you want to dig deeper into understanding how code works in SAS, I recommend you take my free online course and how to use SAS on demand for academics. All these lessons are based on my technical but thought provoking book, Mastering SAS Programming for Data Warehousing. I'll link to these in the description. Thanks for watching and have a spontaneous day.