How Role Elements Appear in the Velocity Code

For each role, a Velocity variable is used to access the role information. This variable is the same as the role’s name attribute. In the Role element, the minVars and maxVars attributes specify how many variables can be assigned to a specific role. Because roles can have 1 to n number of variables, the corresponding Velocity variable is an array. The syntax for an array is $variable-name[index-number]. In this example, $subsetRole is the Velocity variable for the Subset by role (which is defined in the metadata):
proc rank data=$dataset (where=($subsetRole[0]="$filterValue"))descending
You can use the Velocity variable’s GET method to obtain the attributes for each role variable. The GET method takes a string parameter that accepts one of these values:
Attribute
Description
format
specifies the SAS format that is assigned to the variable.
informat
specifies the SAS informat that is assigned to the variable.
length
specifies the length that is assigned to the variable.
type
specifies the type of variable. Valid values are Numeric or Char.
value
specifies the name of the variable.
In this example, the Analysis Group role is given the name of BY. As a result, the Velocity variable, $BY, is created. When this script is run, the $BY variable is checked to see whether any columns are assigned. If the user has assigned any columns to the Analysis Group role, the generated SAS code sorts on these columns. To demonstrate the GET method, only numeric variables are added.
<DataSources>
   <DataSource name="DATASOURCE">
      <Roles>
         <Role type="A" maxVars="0" order="true" minVars="0" 
         name="VAR">Columns</Role>
         <Role type="A" maxVars="0" order="true" minVars="0" 
         name="BY">Analysis group</Role>
         <Role type="N" maxVars="0" order="true" minVars="0" 
         name="SUM">Total of</Role>
         <Role type="A" maxVars="0" order="true" minVars="0" 
         name="ID">Identifying label</Role>
      </Roles>
   </DataSource>
</DataSources>
<CodeTemplate>
   <![CDATA[
#if( $BY.size() > 0 )/* Sort $DATASOURCE for BY group processing. */

PROC SORT DATA=$DATASOURCE OUT=WORK.SORTTEMP;
   BY #foreach($item in $BY ) #if($item.get('type') == 'Numeric' $item #end#end;
#end
RUN;]]>
</CodeTemplate>