 Hi there, it's me, Monica Wahee, accompanying you as we proceed toward a deeper understanding of SaaS on Demand for Academics, otherwise known as SaaS ODA. In this video, I'm going to show you how to add conditional programming to a SaaS macro I already built. Okay, here we are in the SaaS on Demand for Academics, or SaaS ODA environment. If you need help setting up your free account in SaaS ODA, you can take my free online course that will help you, which is called Getting Started with SaaS ODA. Name is short, sweet, and to the point. I'll link you to it in the description. Okay, assuming you got started with SaaS ODA, you now know how to open a program window and put some code in it. So please, if you want to follow along, go get this code from GitHub and paste it into a program window. Now, before we start here in program one, I want to go to program two, where we have code for a macro from my previous video. You might remember what we were doing. We were using data from an annual phone survey done about health topics in the United States called the Behavioral Risk Factor Surveillance System, or BRFSS. We had a bunch of questions in the survey where the respondent was asked if they had various conditions, like asthma, heart attack, and heart disease. We wanted to make binary flag variables for each condition because the coding of the native variables was messy. So we made this macro called make underscore flag, which allowed us to input parameters into the macro each time we ran it. So first, we ran it by putting in the native variable asthma3 for asthma. That's for macro variable native underscore var. And then the new transform flag was designated asthma underscore flag. That is the macro variable flag underscore var. And then we used my handy dandy SAS naming conventions to set the names of the input data set, macro variable data underscore in, and the output data set, macro variable data underscore out. As I mentioned before, I increment the suffix character in the output data set from the input data set so we have a rollback point. If you watch the previous video, you will see I successfully built this macro and I ran it on the asthma variable. But then you'll see I call the macro two more times. First to make a heart attack flag and then to make a heart disease flag. Actually, let's just run all this code to get our data set up to speed. Okay, good. That ran. Now, let's go to program one where we have the code I'm going to focus on in this video. All the variables for the various conditions, asthma, heart attack, heart disease, they were all coded such that one equals yes and every other value was some version of not yes, either no or unknown, but definitely not yes. The flag was set to one for all the yeses. But with the diabetes three variable, which is where they asked the respondent if they have diabetes, you can answer one for yes, but you can also answer two for yes, which means yes, but only during pregnancy. Also three is no, but four is pre-diabetes. Some people might include four and yes, but we are just making a rule that the flag for diabetes three is going to include native values one and two, not just one as with our other condition variables. So let's start by diagnosing our macro. The macro and the men's statements look a lot like the base macro we are modifying to make this conditional macro, except you will see that we named this macro make underscore flag underscore conditional instead of make underscore flag. But it has the same parameters, meaning it's asking for the same macro variable arguments when you launch the macro. But here's what's new. We have this if else macro programming. So we are starting by telling SAS if the native variable is the diabetes variable diabetes three, then do this first code. Usually you take the weirder cases and put them first. That way you have SAS deal with all the odd balls first, then go on to grind through the rest of the situations. The main thing I want you to see in the macro programming is the lines we added to this code to handle the if else programming. First we see this line that says if native underscore var equals diabetes three, then do. And you can see all these percent signs before if, then, and do. Also remember how the ampersand indicates we are filling in a macro variable? So we know that native underscore var is referring to whatever the value of the parameter is that we said when we launched the macro for native underscore var. So if we told SAS native underscore var was diabetes three when we launched the macro, then we are telling SAS here to do the code that is following this then do statement. But if it's not diabetes three, it's like asthma three or one of the other variables coded a different way than don't do. Actually that's here. See how it says end? When we told SAS above that it should do something special, if the native variable is diabetes three, we have to be clear about when the instructions stop. So this end is the end of the do instructions. Then the next line else do tells SAS what to do if it's not diabetes three, which actually is our base macro. You probably recognize it. But since we now have a conditional in here, we have to put an end at the end of this code. So now we have closed both of our do's with ends. And then we just throw in our two-way proc freak at the bottom, comparing our native variable to our transform variable to make sure it's cool. All right, let's start by running this macro and just putting it into SAS's memory. I'll highlight the whole thing. Macro to mend, then run. Uneventful. It always is this way. No feedback from SAS. That's what happens when you just run the macro to load it. You have to launch it to hear what SAS thinks of it. OK, let's go back to our code and launch it. OK, notice that when I first launch it, I carry on from our previous code. I feed it native variable CVDSTRK3, which is if the respondent has ever had a stroke. And I make the variable stroke underscore flag. As you know, we are on BRFSS underscore D, so I make that the input data set and output BRFSS underscore E. Let's highlight and run this and see if SAS figures out which code to run, the Diabetes 3 code or the code at the bottom. OK, well, technically we should look in the log file, but I'm in a hurry. I can already tell that the native values of CVDSTRK3 look normal. And they were coded right in stroke underscore flag, so I'm just going to skip the log file and go back to our code. After all, I'm much more worried about recoding Diabetes 3. OK, now the true test. Let's launch the macro with this next code where our native variable is Diabetes 3, and we are making Diabetes underscore flag. Let's see if SAS figures out which part of the conditional macro to run. I'm going to highlight and run this. Well, lookie-loo here. See all these values of Diabetes 3? And see how in Diabetes underscore flag, it is coded as 1 for both the 1 and the 2 values of Diabetes 3? That looks right, but let's sneak a peek at the log file just to be sure. Actually, we don't really see much in the log file. I already know from working on this code that it is running right, but when I was building it, I had a lot of trouble. I don't want to pretend it was easy. And I needed to do a lot of troubleshooting with macros, and it's not easy when the log file doesn't tell you much. That's why I included chapter 9 in my book, Mastering SAS Programming for Data Warehousing, where I go over strategies for troubleshooting macros, including using put statements. But you'll have to read about it in the book. But at least I was able to show you how to add a condition to a macro. And you can see that if this were a real data warehouse and we were building ETL code, we'd probably be throwing a lot more conditions into this macro. BRFSS has some new marijuana-related variables in it, and they have some diverse coding. So I can imagine that people running SAS data warehouses with BRFSS data in them had to add some new conditions to their macros for transforming these variables as they came online. Want to learn more about the different features of SAS? You can start by taking my free online course on how to use SAS on demand for academics. All these lessons are based on my easy to understand yet in depth book, Mastering SAS Programming for Data Warehousing. I'll link to these in the description. Thanks for watching and have an uplifting day.