How to Add a Flag Variable to a Dataset in SAS ODA – Demonstration
Channel: Monika Wahi
Date: 2021-11-25

*Note: I may be compensated, but you will not be charged, if you click on the links below.

💡 If you are a public health practitioner looking for a targeted program for enhancing your data science skills, please sign up to participate in my 30-minute market research interview so I can get your feedback: https://buff.ly/3UnLqmq

In this video, Monika Wahi shows you how to at a flag variable to a data set during a SAS data step.

GITHUB
Access code and dataset here: https://buff.ly/3xxhcEB 
 
Need help importing the dataset? Watch this video: https://youtu.be/mHhT0Bs4Rmo
Want more info on PROC FREQ? Watch:
💿 this video: https://youtu.be/0jmzYjSGdnI and
📀 this video: https://youtu.be/yNItcDey9Tk 
“PROC FREQ: It’s More Than Counts” SAS white paper by Richard Severino: https://support.sas.com/resources/papers/proceedings/proceedings/sugi25/25/btu/25p069.pdf


COURSE & BOOK
💿Want to start using free, online SAS OnDemand for Academics – but don’t know how? Take Monika’s FREE online course, “Getting Started with SAS OnDemand for Academics (ODA): https://buff.ly/3CQVPxG 
📀Want to run a SAS data warehouse? Learn how by reading Monika’s book, “Mastering SAS Programming for Data Warehousing”: https://buff.ly/31Hz1mg  

WANT TO SUPPORT MONIKA ON SOCIAL MEDIA?
❤️Subscribe to Monika's YouTube channel: https://buff.ly/2W6ijuc   
🧡Follow/connect with Monika on LinkedIn: https://www.linkedin.com/in/dethwench/ 
💛Follow Monika on Twitter: https://twitter.com/PHExaminer 
💚Try Monika’s courses on LinkedIn Learning: https://linkedin-learning.pxf.io/NKN0JO 
💙Try Monika's boutique research methods and data science courses here: https://buff.ly/3zM243P 


Timestamps for easy navigation:
00:58 What we are doing in this video – adding a variable through using a data step.
01:09 Description of example dataset – Behavioral Risk Factor Surveillance System (BRFSS): https://buff.ly/311uQ1y
01:20 Previous video showing how to import the dataset: https://youtu.be/mHhT0Bs4Rmo
01:28 Description of data step processing we are going to cover, and variable names
02:02 Explanation of input/output commands in data step, and naming conventions of datasets
02:42 Read Chapter 4 of Monika’s book, “Mastering SAS Programming for Data Warehousing”, for her guide to SAS dataset, code, variable, macro and array naming conventions: https://buff.ly/31Hz1mg
03:09 Reviewing data step code that edits the dataset (between the set statement and run)
03:28 Description of a binary flag variable (for asthma), and why you like to add them in data science
04:05 Description of two-step approach to making binary variable
04:34 Pros and cons of using the two-step approach. It causes issues with SAS’s program data vector (PDV).
* More information on the PDV here: https://v8doc.sas.com/sashtml/lrcon/z0961108.htm
* More information on the “else” statement from Boston University: https://sphweb.bumc.bu.edu/otlt/mph-modules/bs/sas/sas-basics1/sas-basics16.html 
05:05 Why should you START with “clumsy” and “inefficient” SAS code and build it up slowly, rather than trying to program efficiently
05:19 We use a PROC FREQ before the run statement to check the transformed variable. To learn PROC FREQ, watch this video: https://youtu.be/0jmzYjSGdnI
06:15 “Missing” option on the PROC FREQ tables command causes “missings” in a separate category
06:46 “list” option on PROC FREQ makes the output less unwieldy because it is in a list, and not tabular. Monika shows a screen shot of tabular PROC FREQ output from “PROC FREQ: It’s More Than Counts” SAS white paper by Richard Severino: https://support.sas.com/resources/papers/proceedings/proceedings/sugi25/25/btu/25p069.pdf 
07:28 Running code and reviewing list output to verify that the flag was recoded properly
08:09 At this point, it is possible to edit the code to make it more efficient, because you can benchmark it against the verified correct output of this more clumsy code
08:20 Always run a two-way PROC FREQ after you recode a variable that includes the base variable and the recoded variable. That way, you can make sure it was recoded properly.

How to Add a Flag Variable to a Dataset in SAS ODA – Demonstration