DYNAMIC, MVAR, and NMVAR Statements

Each of the DYNAMIC, MVAR, and NMVAR statements can define multiple variables and an optional text-string denoting its purpose or usage. For example:
DYNAMIC YVAR "required" YLABEL "optional"; 
MVAR LOCATE "INSIDE or OUTSIDE" SYSDATE;
NMVAR TRANS "transparency factor";
Note: For template readability, it is helpful to adopt a naming convention for these variables to distinguish them from actual option values or column names. Common conventions include capitalization, or adding leading or trailing underscores to their names.
Dynamics and macro variables can be referenced within the template definition as
  • argument or option values. For example:
    seriesplot x=date y=YVAR / curvelabel=YLABEL  
      curvelabellocation=LOCATE datatransparency=TRANS;
      
  • parts of some text strings. For example:
    entrytitle "Time Series for " YLABEL; 
    entryfootnote "Created on " SYSDATE;
    
Dynamics and run-time macro variable references cannot resolve to statement or option keywords.
Note that macro variable references should not be prefaced with an ampersand (&) if you want them to resolve at run time.
Macro variables defined by MVAR are strings when they resolve, as with SYMGET() in the DATA step.
Macro variables defined by NMVAR are converted to numeric tokens when they resolve, as with SYMGETN() in the DATA step.
The values for a dynamic variable do not have to be provided by the data source. Rather, you can provide the values in the DYNAMIC statement in PROC SGRENDER, specifying the values as a space delimited list, enclosed in quotation marks. Do not use parentheses in the specification.
In the following example, the graph template specifies a dynamic variable named TICKS, which is referenced on the XAXISOPTS= option in LAYOUT OVERLAY. The DYNAMIC statement in PROC SGRENDER provides values for TICKS:
proc template;
  define statgraph regress;
    dynamic TICKS ;
    begingraph;
      layout overlay /xaxisopts=(linearopts=(tickvaluelist=TICKS));
        scatterplot x=age y=weight;
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=regress;
  dynamic TICKS="11 13 16" ;
run;
If your template uses a dynamic variable to specify a required attribute, such as a variable name, and the name is misspelled or is not provided in the SGRENDER procedure, then a warning is issued and the respective plot statement drops out of the final graph. A graph is produced, but it might be a blank graph, or it might show the results of all statements except those that are in error.
For more information about using dynamics and macro variables in your templates, see SAS Graph Template Language: User's Guide.