*! version 1.0.1 24apr1996 program define var_get /* Syntax: var_get key [varname] [, OPTional REQuired] If "optional" specified, it will not produce an error message if varname is not given and name is not set. Note: "required" is the default. Output: global S_1 "varname" */ version 4.0 parse "`*'", parse(" ,") local key "`1'" macro shift var_key chk_key `key' $S_1 if "`1'"!="," & "`1'"!="" { local varlist "req ex max(1)" } local options "OPTional REQuired" parse "`*'" if "`optiona'"!="" & "`require'"!="" { error 198 } if "`varlist'"!="" { local muststr : word $S_1 of $S_2 capture confirm string variable `varlist' if _rc==0 & `muststr' { di in red "`key'() may not be a string variable" exit 109 } char _dta[`key'] `varlist' global S_1 "`varlist'" exit } global S_1 : char _dta[`key'] if "$S_1"=="" & "`optiona'"=="" { di in red "`key'() required" exit 100 } end program define chk_key /* checks syntax of key */ version 4.0 local key "`1'" local i 2 while "``i''"!="" { if "`key'"=="``i''" { global S_1 = `i' - 1 exit } local i = `i' + 1 } di in red "keyword incorrect" error 198 end