How to Use SAS - Special Topic - Macro Coding and Macro Variables
Bitcoin donations are welcome: 1GGV3gbJeA83FWmz9hDfPri8EuqcUtodXy Mike's SAS Tutorials - Special Topic 1 This video series is intended to help you learn how to program using SAS for your statistical needs. This special topic lesson introduces the concept macro programming to accomplish repetitive tasks more easily. I also discuss macro variables, and the concept of passing variables into the macro function. I provide basic methods of converting a simple set of procedures into a macro that can be used as a template to repeat those procedures for any variable. Finally, I work through an example to show how one can use macros to take a variable and create several transformations of it. Helpful Notes: 1. There are two places one can use macro variables: within a macro, and globally outside of all STEPS. 2. The ampersand operator: &, defines a macro variable within a macro and is used to call macro variables anywhere. 3. The %let statement allows you to define macro variables outside of a macro, though the & operator still must be used to call the macro variable elsewhere. 4. The MACRO statement begins the definition of a macro and the MEND ends the definition. 5. It is optional to restate the macro name after the MEND statement. 6. A macro can be thought of as a function, where one passes something into the function and certain things are returned. Unlike a function, however, macros do not always have to return something. Today's Code: data main; input ID var1 var2; cards; 1 2 3 2 4 5 3 6 7 4 8 9 ; run; proc contents data=main; run; /* 1. Create a macro variable using the %let statement */ %let newvar = var3; /* 2. Use the & operator to call a macro variable */ data new_main; set main; &newvar = var1+var2; run; proc contents data=main; run; proc contents data=new_main; run; proc print data=new_main; run; /* 3. Create a macro to transform a variable */ %MACRO transform_this(x); &x._squared = &x ** 2; &x._cubed = &x ** 3; &x._inverse = 1 / &x; %MEND transform_this; data newer_main; set new_main; %transform_this(var1); %transform_this(var2); run; proc print data=newer_main; run; /* 4. Create a macro to run the CONTENTS procedure on any data set */ proc contents data=main; run; proc contents data=new_main; run; proc contents data=newer_main; run; %MACRO contents_of(data_set); proc contents data=&data_set; run; %MEND contents_of; %contents_of(main); %contents_of(new_main);

How to Use SAS - Special Topic - Configuring the SAS Environment for Efficiency

Why Aliens Would NEVER Invade Africa

SAS- Proc Transpose-1

Ex-Google Recruiter Explains Why "Lying" Gets You Hired

SAS Tutorial | How to Create Macro Variables and Use Macro Functions

SAS Online Training - Introduction to SAS software (Part-1)

RStudio Tutorial for Beginners: Introduction to R Studio and Basics of R

SAS Tutorial | 3 Steps to Build a SAS Macro Program

What Is SAS | SAS Tutorial For Beginners | SAS Programming | SAS Training | Edureka

She’s 12. She Sings Aretha Franklin… Until Simon TELLS Her to Do It Acapella! 😳

SAS Tutorial | Using SAS Macro Variable Lists to Create Dynamic Data-Driven Programs

Brain Focus Music ~ No Lyrics Work Playlist for Mental Clarity & Deep Work

Regular Expressions (Regex) - Visually Explained

How to Answer ANY Question (Even If You Don't Know The Answer!)

But what are Hamming codes? The origin of error correction

If You Have A Bad Memory, I’ll Help You Fix It In 28 Minutes

SAS Programming Tutorial For Beginners | Advanced SAS Programming Proc SQL Day 1 | By Pavani

SAS Tutorial | How to convert character to numeric in SAS

