backnextLearning Path
   


Introduction

SAS macro variables enable you to substitute text in your SAS programs. Macro variables can supply a variety of information, including

  • operating system information
  • SAS session information
  • text strings.

When you reference a macro variable in a SAS program, SAS replaces the reference with the text value that has been assigned to that macro variable. By substituting text into programs, SAS macro variables make your programs more reusable and dynamic.

The following sample code shows how a macro variable might be used to substitute a year value throughout a program, enabling you to quickly and easily change the value of year throughout the program:

    %let year=2002;
    proc print data=sasuser.schedule;
       where year(begin_date)=&year;
       title "Scheduled Classes for &year";
    run;
    proc means data=sasuser.all sum;
       where year(begin_date)=&year;
       class location;
       var fee;
       title1 "Total Fees for &year Classes";
       title2 "by Training Center";
    run;

Time to Complete

This lesson contains pages and takes approximately 1.5 hours to complete.



Objectives

In this lesson, you learn to

  • recognize some benefits of using macro variables
  • substitute the value of a macro variable anywhere in a program
  • identify and display automatic macro variables
  • create and display user-defined macro variables
  • recognize how macro variables are processed
  • display macro variable values and other text in the SAS log
  • use macro character functions
  • combine macro references with adjacent text or with other macro variable references
  • use macro quoting functions.

Prerequisites

Before taking this lesson, you should complete the following lessons:

  • .

  Copyright © 2003 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Terms of Use & Legal Information | Privacy Statement
backnext