Stata: Data Analysis and Statistical Software
   >> Home >> Resources & support >> Users Group meetings >> 5th UK meeting

Low-level parsing, revisited

  • gettoken allows token-by-token low-level parsing
  • Useful for two-word commands

    • Pull a subcommand off of the original command line
    • Put the rest of the original command line back in `0' for high-level parsing
              . mycmd6 sum mpg weight if foreign
      
              program define mycmd6              /* `0'      : sum mpg weight if foreign */
                  version 6.0
                  gettoken subcmd 0 : 0          /* `subcmd' : sum                       */
                                                 /* `0'      : mpg weight if foreign     */
                  syntax [varlist] [if] [in]     
                  if "`subcmd'" == "sum" {
                      ...
                  }
                  ...
              end
      
      This is similar to the following in Perl:
              ($subcmd,$zero) = split(/ /,$zero,2) ;
Bookmark and Share 
Meetings
Stata Conference
User Group meetings
Proceedings
Like us on Facebook Follow us on Twitter Follow us on LinkedIn
Follow us
© Copyright 1996–2012 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index   |   View mobile site