SYMGET Function

Returns the value of a macro variable to the DATA step during DATA step execution.
Type: DATA step function
See: RESOLVE Function, SYMGETN Function, CALL SYMPUT Routine, and CALL SYMPUTN Routine



Required Argument

can be one of the following items:
  • the name of a macro variable within quotation marks but without an ampersand. When a macro variable value contains another macro variable reference, SYMGET does not attempt to resolve the reference. If argument references a nonexistent macro variable, SYMGET returns a missing value. This example shows how to assign the value of the macro variable G to the DATA step variable X.
  • the name of a DATA step character variable, specified with no quotation marks, which contains names of one or more macro variables. If the value is not a valid SAS name, or if the macro processor cannot find a macro variable of that name, SAS writes a note to the log that the function has an illegal argument and sets the resulting value to missing. For example, these statements assign the value stored in the DATA step variable CODE, which contains a macro variable name, to the DATA step variable KEY:
    length key $ 8;
    input code $;
    Each time the DATA step iterates, the value of CODE supplies the name of a macro variable whose value is then assigned to KEY.
  • a character expression that constructs a macro variable name. For example, this statement assigns the letter s and the number of the current iteration (using the automatic DATA step variable _N_).


SYMGET returns a character value that is the maximum length of a DATA step character variable. A returned value that is longer is truncated.
If SYMGET cannot locate the macro variable identified as the argument, it returns a missing value, and the program issues a message for an illegal argument to a function.
SYMGET can be used in all SAS language programs, including SCL programs. Because it resolves variables at program execution instead of macro execution, SYMGET should be used to return macro values to DATA step views, SQL views, and SCL programs.


  • SYMGET returns values of macro variables during program execution, whereas the SYMPUT function assigns values that are produced by a program to macro variables during program execution.
  • SYMGET accepts fewer types of arguments than the RESOLVE function. SYMGET resolves only a single macro variable. Using RESOLVE might result in the execution of macros and further resolution of values.
  • SYMGET is available in all SAS programs, but SYMGETN is available only in SCL programs.

Example: Retrieving Variable Values Previously Assigned from a Data Set

data dusty;
   input dept $ name $ salary @@;
bedding Watlee 18000    bedding Ives 16000
bedding Parker 9000     bedding George 8000
bedding Joiner 8000     carpet Keller 20000
carpet Ray 12000        carpet Jones 9000
gifts Johnston 8000     gifts Matthew 19000
kitchen White 8000      kitchen Banks 14000
kitchen Marks 9000      kitchen Cannon 15000
tv Jones 9000           tv Smith 8000
tv Rogers 15000         tv Morse 16000
proc means noprint;
   class dept;
   var salary;
   output out=stats sum=s_sal;
proc print data=stats;
   var dept s_sal;
   title "Summary of Salary Information";
   title2 "For Dusty Department Store";
data _null_;
   set stats;
   if _n_=1 then call symput('s_tot',s_sal);
   else call symput('s'||dept,s_sal);
data new;
   set dusty;
proc print data=new split="*";
   label dept   ="Department"
         name   ="Employee"
         pctdept="Percent of *Department* Salary"
         pcttot ="Percent of *   Store  * Salary";
   format pctdept pcttot 4.1;
   title  "Salary Profiles for Employees";
   title2 "of Dusty Department Store";
This program produces the following output:
Summary of Salary Information
Summary of Salary Information
Salary Profiles for Employees
Salary Profiles for Employees