/*
  recode

*!  VERSION 1.1.1  31mar2005

*/

VERSION 9.0

INCLUDE _std_large
INCLUDE _ht310
INCLUDE header

HELP hlp1, view("help recode")
RESET res1

DIALOG main, label("recode - Recode categorical variables") /*
		*/ tabtitle("Main")
BEGIN
  /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+*/
  TEXT     tx_var          _lft      _top       _iwd     .,		/*
  		*/label("Variables:")
  VARLIST  vl_var          @         _ss        @        .,		/*
  		*/label("Variables")
  TEXT     tx_rule         @         _ls        _comb4_1 .,		/*
	*/label("Choose rule formats to edit or construct your own rules:")/*
  	*/
  BUTTON   bu_rule         _lft4_4   @          _cwd4_1  .,		/*
  	*/label("Examples...")						/*
  	*/push("script help_me")
  TEXT    tx_req           _lft      _ms        _iwd     .,label("Required:")
  COMBOBOX cb_rul1         _lft      _ss        _iwd     .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
  TEXT     tx_opt          @         _ms        @        .,label("Optional:")
  COMBOBOX cb_rul2         @         _ss        @        .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
  COMBOBOX cb_rul3         @         _ms        @        .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
  COMBOBOX cb_rul4         @         _ms        @        .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
  COMBOBOX cb_rul5         @         _ms        @        .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
  COMBOBOX cb_rul6         @         _ms        @        .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
  COMBOBOX cb_rul7         @         _ms        @        .,		/*
	*/label("Choose rule formats to edit or construct your own rules")/*
  		*/contents(rules) dropdown append			/*
		*/
END

INCLUDE ifin

DIALOG opt, label("") /*
		*/ tabtitle("Options")
BEGIN
  /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+*/
  GROUPBOX gb_gen          _lft      _top       _iwd     _ht11h,	/*
	*/label("Create new variables or replace existing ones?")
  RADIO    rb_rep          _indent   _ms        _ibwd    .,		/*
  		*/label("Replace existing variables") /*
  		*/first 						/*
		*/clickon(script rep_on)				/*
		*/option("NONE")
  DEFINE holdx @x
  RADIO    rb_gen          @         _ms        @        .,		/*
  		*/label("Generate new variables:")			/*
  		*/clickon(script gen_on) 				/*
		*/option("NONE")
  EDIT     ed_gen          _indent2  _ss        _inwd    .,		/*
  		*/label("Generate new variables") option(generate)
  RADIO    rb_pre          holdx     _ms        _ibwd    .,		/*
  		*/label("Generate new variables with this prefix:")	/*
  		*/option("NONE") 					/*
		*/clickon(script pre_on)				/*
		*/last
  EDIT     ed_pre          _indent2  _ss        _vnwd    .,		/*
  		*/label("Generate new variables with prefix")		/*
  		*/default("new_") 					/*
		*/max(32) option(prefix)
  CHECKBOX ck_lab          _lft      _xls       _iwd     .,		/*
*/label("Specify a name for the value label defined by the transformation rules:")/*
		*/clickon(gaction opt.ed_lab.enable)			/*
		*/clickoff(gaction opt.ed_lab.disable)
  EDIT     ed_lab          _indent2  _ss        _inwd    .,		/*
*/label("Specify a name for the value label defined by the transformation rules")/*
		*/max(32) option("label")
  CHECKBOX ck_copy         _lft      _ls        _iwd     .,		/*
  		*/label("Copy out-of-sample values from original variables")/*
  		*/option("copyrest")

  CHECKBOX ck_test         @         _ls        @        .,		/*
		*/label("Test that rules are invoked and do not overlap")/*
		*/option("test")
END

SCRIPT help_me
BEGIN
  view help recode_rules##|_new
END

SCRIPT rep_on
BEGIN
  opt.ed_gen.disable
  opt.ed_pre.disable
END

SCRIPT gen_on
BEGIN
  opt.ed_gen.enable
  opt.ed_pre.disable
END

SCRIPT pre_on
BEGIN
  opt.ed_gen.disable
  opt.ed_pre.enable
END

LIST rules
BEGIN
  (# = #)
  (#/# = #)
  (# # = #)
  (#/# # = #)
  (nonmissing = #)
  (missing = #)
  (else = #)
  (# = # "label")
  (#/# = # "label")
  (# # = # "label")
  (#/# # = # "label")
  (nonmissing = # "label")
  (missing = # "label")
  (else = # "label")
END

PROGRAM command
BEGIN
	put "recode "
	varlist main.vl_var
	put " "
	require main.cb_rul1
	put main.cb_rul1
	put " "
	put main.cb_rul2
	put " "
	put main.cb_rul3
	put " "
	put main.cb_rul4
	put " "
	put main.cb_rul5
	put " "
	put main.cb_rul6
	put " "
	put main.cb_rul7
	INCLUDE _ifin_pr
	beginoptions
		if opt.rb_gen {
			require opt.ed_gen
			optionarg opt.ed_gen
		}
		if opt.rb_pre {
			require opt.ed_pre
			optionarg opt.ed_pre
		}
		if opt.ck_lab {
			require opt.ed_lab
			optionarg opt.ed_lab
		}
		option opt.ck_copy
		option opt.ck_test
	endoptions
END
