 Hi there, it's me, Monica Wahee, giving you some demonstrations on the use of SAS on demand for academics, otherwise known as SAS ODA. In this video, I'm going to show you how to read in a SAS dataset, then split it into a bunch of different output datasets based on where criteria I place on one of the variables. Okay, I'm going to show you this code in kind of a weird order. First you have to go get this dataset from GitHub. It's called chap 8 underscore 2, and it's a SAS dataset. Then you need to create a folder like I have named x, then upload the SAS dataset to that folder. Then after that, you have to map that to libname x so SAS ODA can find your dataset. I have links to videos you can watch if you don't know how to do that. So what I want to show you in SAS is how you can use a dataset to read in a big dataset, then set criteria on one of the variables, and have SAS split the output datasets based on those criteria. So you see this code, I'm going to confess, I cheated. I already ran this code. The reason I did that is so that way I could show you what the dataset looks like in the output data tab. So the dataset we are reading in, chap 8 underscore 2, has the same structure as the datasets we are splitting and exporting. They all just have these two columns, underscore state, which stands for a code for the state in the United States, and f month, which stands for file month. Now in real life, if you run a real data warehouse, you might have a bunch of other columns. When I worked at the army, we might get a dataset like this, and our file month would be January, and maybe the year would be 2011, and we'd have a list of rows for every service member who did something that month, like join the army, or maybe retired from the army. Sometimes we join these datasets, sometimes we'd split them. When we'd split them by month, we'd do something like what I'm showing you here. So say we want to split this big dataset into 12 datasets. And for each month, see these rows just say one January? Well if we page forward in the dataset, we'd see eventually the other months. Two for February, three for March, and so on. So the idea is we want to split the dataset by this f month variable into monthly files. Let's go back to our code. So here's the code. Let me talk about this code in three parts. First we have the data command. This command declares the names of all the output datasets we plan to make in this dataset. Then we have the set command, which tells SAS which dataset to read in for this operation. Of course it's our big dataset, chap 8 underscore 2. Then here we have all of our conditionals with output commands. See if f month equals 1, then output x dot jan 2018. So that tells SAS that for all the records where f month equals 1, put them in the output dataset named x dot jan 2018. And you can guess what the rest of the commands mean. So we should theoretically have 12 datasets after we do this, provided we have records for every month. Before I run this, I just want to make a point, and that is that this code is very error prone. You have to declare all the output datasets after the data command, and then you have to repeat them below when doing the output commands. If you mistype any of this or anything here doesn't match, you'll get an error. Okay, let's run this. If it works, we should see a bunch of new datasets appear on the left in our X folder. See that? There they are. Awesome. The reason I go over this is that if you run a SAS data warehouse, you spend a lot of time manicuring ETL code like this. If you want to learn more about data warehousing, please check out my book, Mastering SAS Programming for Data Warehousing. I hope you enjoyed this video. Thanks for watching and have a super duper day.