TEMPLATE Procedure: Creating Markup Language Tagsets

Example 2: Creating a Tagset by Copying a Tagset's Source

Features:

SOURCE statement

DEFINE TAGSET statement: : DEFINE EVENT statement

Details

This example copies the source for a tagset that SAS supplies, modifies the template, and then builds a new tagset for custom output. To create a new tagset, use the SOURCE statement in PROC TEMPLATE to copy a tagset's source. Then you can customize the template as necessary.

Program

proc template;
      source tagsets.csv;
run; 

Program Description

Copy the SAS tagset to an external file. The following statements copy the tagset source from the SAS tagset Tagsets.CSV to the SAS log.
proc template;
      source tagsets.csv;
run; 

Partial Log: Default CSV Tagset That SAS Supplies

1    proc template;
NOTE: Writing HTML Body file: sashtml.htm
2          source tagsets.csv;
define tagset Tagsets.Csv;
   notes "This is the CSV definition";
   mvar _CURRENCY_SYMBOL _DECIMAL_SEPARATOR _THOUSANDS_SEPARATOR _CURRENCY_AS_NUMBER
      _PERCENTAGE_AS_NUMBER _DELIMITER;

   define event initialize;

      trigger set_options;

      trigger documentation;

      trigger compile_regexp;
   end;

   define event options_set;

      trigger set_options;

      trigger documentation;

      trigger compile_regexp;
   end;

   define event documentation;

      trigger help /if cmp( $options["DOC"], "help");

      trigger quick_reference /if cmp( $options["DOC"], "quick");
   end;

   define event help;
      putlog "==============================================================================";
      putlog "The CSV Tagset Help Text.";
      putlog " ";
      putlog "This Tagset/Destination creates output in comma separated value format.";
      putlog " ";
      putlog
            "Numbers, Currency and percentages are correctly detected and show as numeric


 ...more lines of log...



define event warning;
   break /if ^$notes;
   put VALUE NL;
end;
mapsub = "/""""/";
map = """";
registered_tm = "(r)";
trademark = "(tm)";
copyright = "(c)";
output_type = "csv";
stacked_columns = OFF;
end;
NOTE: Path 'Tagsets.Csv' is in: SASHELP.TMPLMST.
3    run;
NOTE: PROCEDURE TEMPLATE used (Total process time):
      real time           13.14 seconds
      cpu time            0.63 seconds



Create the customized tagset. Submit the following PROC TEMPLATE code to create the customized tagset Tagsets.Mycsv. The DEFINE EVENT TABLE statement uses the PUT NL statements to add two blank lines to the output file. One blank line is placed before the table and the other is placed after the table.
proc template;
define tagset Tagsets.mycsv;
   notes 'This is the My CSV template';
   define event table;
      start:
         put nl;
      finish:
         put nl;
   end;
   define event put_value;
      put VALUE;
   end;
   define event put_value_cr;
      put VALUE NL;
   end;
   define event row;
      finish:
         put NL;
   end;
   define event header;
      start:
         put ',' /if ^cmp( COLSTART, '1');
         put '''';
         put VALUE;
      finish:
         put '''';
   end;
   define event data;
      start:
         put ',' /if ^cmp( COLSTART, '1');
         put '''';
         put VALUE;
      finish:
         put '''';
   end;
   define event colspanfill;
      put ',';
   end;
   define event rowspanfill;
      put ',' /if ^exists( VALUE);
   end;
   define event breakline;
      put NL;
   end;
   define event splitline;
      put NL;
   end;
   registered_tm = '(r)';
   trademark = '(tm)';
   copyright = '(c)';
   output_type = 'csv';
   stacked_columns = OFF;
end;
end;
To view the customized CSV tagset Tagsets.Mycsv, submit the following code:
proc template;
   source tagsets.mycsv;
run;

Log Output: Customized CSV Tagset Tagsets.Mycsv

You can view the tagset by going to Resultsthen selectTemplatesthen selectSasuser.Templatthen selectMycsv.

proc template;
   define tagset Tagsets.Mycsv / store = Sasuser.Templat;
      notes 'This is the My CSV template';
      define event table;
         start:
            put NL;
         finish:
            put NL;
      end;
      define event put_value;
         put VALUE;
      end;
      define event put_value_cr;
         put VALUE NL;
      end;
      define event row;
         finish:
            put NL;
      end;
      define event header;
         start:
            put ',' /if ^cmp( COLSTART, '1');
            put '''';
            put VALUE;
         finish:
            put '''';
      end;
      define event data;
         start:
            put ',' /if ^cmp( COLSTART, '1');
            put '''';
            put VALUE;
         finish:
            put '''';
      end;
      define event colspanfill;
         put ',';
      end;
      define event rowspanfill;
         put ',' /if ^exists( VALUE);
      end;
      define event breakline;
         put NL;
      end;
      define event splitline;
         put NL;
      end;
      output_type = 'csv';
      copyright = '(c)';
      trademark = '(tm)';
      registered_tm = '(r)';
      stacked_columns = OFF;
   end;
run;