Minimal Required Syntax

Consider the following simple GTL template definition:
proc template;
define statgraph mygraphs.scatter;
  begingraph;
    layout overlay;
      scatterplot X=height Y=weight;
    endlayout;
  endgraph;	
end;
run;
Both PROC SGRENDER and the DATA step can be used to execute this template. Both techniques minimally require you to specify the input data source and the template name. Behind the scenes in both cases, an ODS data object is populated and bound to the template. The data object is then passed to a graph renderer, which processes the data and graph request to produce an output image.
The PROC SGRENDER syntax is simple. It uses the DATA= option to specify the data source and the TEMPLATE= option to specify the template to use for rendering the graph:
proc sgrender data=sashelp.class template=mygraphs.scatter; 
run;
The DATA step syntax is slightly more complex. To execute a GTL template, the DATA step FILE and PUT statements provide syntax that is specific to ODS. You must minimally specify the following:
data _null_;
  set sashelp.class;
  file print ods=(template="mygraphs.scatter");
  put _ods_;
run;
  • The DATA step uses keyword _NULL_ for the data set name so that the DATA step executes without writing observations or variables to an output data set. The input data source is defined with a SET statement. This approach is appropriate in the current example, but the input data source can be defined with any appropriate DATA step syntax (INPUT with DATALINES, INPUT with INFILE, SET, MERGE, UPDATE, and so on).
  • FILE PRINT ODS directs output to ODS. PRINT is a reserved fileref that is required when executing a GTL template. It directs output that is produced by any PUT statements to the same file as output that is produced by SAS procedures. The TEMPLATE= specification is required to specify the input template name.
  • The PUT _ODS_ statement, also required, writes the necessary variables to the output object for each execution of the DATA step.
Note: The necessary variables for the output data object are the ones defined by the graph template (in this case, HEIGHT and WEIGHT), not the input data source. As with other DATA step or procedure processing, if you know exactly which variables the template uses, you can restrict the input variables with DROP= or KEEP= input data set options for slightly more efficient processing.