Obtaining Macro Variable Values during DATA Step Execution

The SYMGET Function

Earlier you learned how to use the SYMPUT routine to create macro variables in a DATA step. You are also familiar with using a macro variable reference such as &macvar to obtain the value of a macro variable before a DATA step executes. Now, suppose you want to obtain the value of a macro variable during DATA step execution. You can obtain a macro variable's value during DATA step execution by using the SYMGET function. The SYMGET function returns the value of an existing macro variable.
General form, SYMGET function:
SYMGET(macro-variable)
Here is an explanation of the syntax:
macro-variable
can be specified as one of the following:
  • a macro variable name, enclosed in quotation marks
  • a DATA step variable name whose value is the name of a macro variable
  • a DATA step character expression whose value is the name of a macro variable.

Example

You can use the SYMGET function to obtain the value of a different macro variable for each iteration of a DATA step. In this example, the data set variable Teacher is assigned the value of the macro variable teachn for each observation in the Sasuser.Register data set, where n is the value of the data set variable Course_number for that observation.
Note: This example assumes that a macro variable named teachn has already been created for each observation in Sasuser.Register.
data teachers;
   set sasuser.register;
   length Teacher $ 20;
   teacher=symget('teach'||left(course_number));
run;

proc print data=teachers;
   var student_name course_number teacher;
   title1 "Teacher for Each Registered Student";
run; 
Output Using the SYMGET Function
Part of the SAS output that this program creates is shown below. Notice that the new data set Teachers contains a variable named Teacher and that the values of this variable are the same as the values of the macro variables teach1-teach3 in the global symbol table above.
Teacher for each registered student
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.237.79