*! version 1.0.0 <12Mar98> STB-43 dm56 ** Author: John R. Gleason, Syracuse University, Syracuse NY, USA ** (loesljrg@ican.net) program define labedit version 5.0 macro drop DB* global DB_DBuf 5 ** global DB_DSL : data label /* doesn't work yet, but ... */ local varlist opt local options "Novalue" parse "`*'" global DB_var "`varlist'" parse "`varlist'", parse(" ") global DB_NV1 0 /* #(vars) */ while "`1'" != "" { global DB_NV1 = $DB_NV1 + 1 global DB_v${DB_NV1} "`1'" mac shift } global DB_DBuf1 = min($DB_NV1, $DB_DBuf) global DB_DBuf0 = $DB_DBuf qui if "`novalue'" == "" { tempfile golly lab save _all using `golly' capture confirm file `golly' if !_rc { preserve infile str8 x using `golly', clear keep if x[_n-2] == "label" & x[_n-1] == "define" sort x global DB_NV0 0 while $DB_NV0 < _N { global DB_NV0 = $DB_NV0 + 1 local t = x[$DB_NV0] global DB_vlu "${DB_vlu}`t' " } restore nobreak { lab drop _all run `golly' } } } global DB_ex "exit 3000" window control button "Exit" 292 4 30 8 DB_ex escape global DB_hlp "whelp labedit" window control button "Help" 292 13 30 8 DB_hlp help window control static DB_NV1 5 4 65 30 blackframe global DB_Vars "$DB_NV1 Variables" window control static DB_Vars 8 6 59 8 center window control scombo DB_var 8 13 59 85 DB_VarX global DB_Vsel "VLab1" window control button "Select Variable" 8 24 59 8 DB_Vsel window control static DB_NV1 73 4 97 30 blackframe global DB_Vals "$DB_NV0 Value Labels" wind control static DB_Vals 76 6 59 8 center window control scombo DB_vlu 76 13 59 85 DB_ValX global DB_vsel "VLab0" window control button "Select Label" 76 24 59 8 DB_vsel global DB_UDir "List dir" window control button "Dir" 137 6 30 8 DB_UDir global DB_ULst "List list DB_ValX" window control button "List" 137 15 30 8 DB_ULst global DB_Uqry "UpDate0 1" window control button "Query" 137 24 30 8 DB_Uqry global DB_FND "File last saved: $S_FNDATE" window control static DB_FND 174 6 115 8 global DB_Dsav "Save" window control button "New Dataset Label" /* */ 174 15 75 8 DB_Dsav window control edit 174 24 145 8 DB_DSL maxlen 31 window control static DB_NV1 5 44 317 59 blackframe global DB_Brows 0 window control check "Browse" 5 37 40 6 DB_Brows global DB_Fh0 "No." global DB_Fh2 "Value Label" window control edit 119 50 53 8 DB_val1 maxlen 8 window control edit 119 60 53 8 DB_val2 maxlen 8 window control edit 119 70 53 8 DB_val3 maxlen 8 window control edit 119 80 53 8 DB_val4 maxlen 8 window control edit 119 90 53 8 DB_val5 maxlen 8 window control edit 174 50 145 8 DB_buf1 maxlen 31 window control edit 174 60 145 8 DB_buf2 maxlen 31 window control edit 174 70 145 8 DB_buf3 maxlen 31 window control edit 174 80 145 8 DB_buf4 maxlen 31 window control edit 174 90 145 8 DB_buf5 maxlen 31 window control static DB_Buf1 40 50 19 8 right window control static DB_Buf2 40 60 19 8 right window control static DB_Buf3 40 70 19 8 right window control static DB_Buf4 40 80 19 8 right window control static DB_Buf5 40 90 19 8 right window control static DB_Nam1 62 50 53 8 right window control static DB_Nam2 62 60 53 8 right window control static DB_Nam3 62 70 53 8 right window control static DB_Nam4 62 80 53 8 right window control static DB_Nam5 62 90 53 8 right global DB_Top "Scroll 0" window control button "Top" 8 47 30 8 DB_Top global DB_PgUp "Scroll -$DB_DBuf" window control button "PgUp" 8 56 30 8 DB_PgUp global DB_Up "Scroll -1" window control button "Up" 8 65 30 8 DB_Up global DB_Dn "Scroll 1" window control button "Dn" 8 74 30 8 DB_Dn global DB_PgDn "Scroll $DB_DBuf" window control button "PgDn" 8 83 30 8 DB_PgDn global DB_Bot "Scroll ." window control button "Bottom" 8 92 30 8 DB_Bot VLab1 window control static DB_Fh0 49 37 10 6 right window control static DB_Fh1 85 37 30 6 right window control static DB_Fh2 119 37 53 6 center window control static DB_Fh3 174 37 145 6 center capture noi window dialog "Labels Editor > $S_FN" . . 330 117 macro drop DB* exit 0 end program define ClrBuf local i 0 while `i' < $DB_DBuf { local i = `i' + 1 global DB_buf`i' " " global DB_val`i' " " if "$DBIsVar" == "0" { global DB_Nam`i' "" } } end program define UpDate1 local i 0 while `i' < $DB_DBuf1 { local i = `i' + 1 local j ${DB_Buf`i'} local t = trim("${DB_buf`i'}") lab var ${DB_v`j'} "`t'" local t : type ${DB_v`j'} if !index("`t'", "str") { lab val ${DB_v`j'} ${DB_val`i'} } } end program define UpDate0 if "$DB_ValX" == "" { window stopbox stop "Select or assign a" "value label name" exit } local i 0 while `i' < $DB_DBuf { local i = `i' + 1 local j = trim("${DB_buf`i'}") if "`j'" != "" { qui cap confirm integer number `j' if !_rc { qui cap assert `j' >= 0 } if _rc { window stopbox stop "`j' is not a" "non-negative integer" exit } if "`1'"=="1" { global DB_val`i' : label $DB_ValX `j' } else { local t = trim("${DB_val`i'}") if "`j'" != "`t'" { if "`t'" != "" { local t "${DB_val`i'}" } lab def $DB_ValX `j' "`t'", modify global DB_DBuf0 = max($DB_DBuf0, `j'+1) } } } } end program define Scroll if !$DB_Brows { UpDate${DBIsVar} } local t `1' if "`1'" == "." { local t = cond("$DBIsVar"=="1", $DB_NV1, $DB_DBuf0)-$DB_DBuf+1 } else if "`1'" != "0" { local t = `1' + $DB_Buf1 } if "$DBIsVar" == "1" { local t = min($DB_NV1-$DB_DBuf+1, `t') } local t = max(1, `t') Draw${DBIsVar} `t' end program define Draw1 local i `1' local j 0 while `j' < $DB_DBuf1 { local j = `j' + 1 global DB_Nam`j' "${DB_v`i'}" local t : variable label ${DB_v`i'} global DB_buf`j' "`t' " local t : type ${DB_v`i'} if index("`t'", "str") { local t "" } else { local t : value label ${DB_v`i'} } global DB_val`j' "`t' " global DB_Buf`j' `i' local i = `i' + 1 } end program define Draw0 local i `1' local j 0 while `j' < $DB_DBuf { local j = `j' + 1 global DB_Buf`j' `i' local t = `i' - 1 global DB_buf`j' "`t'" local tt if "$DB_ValX" != "" { local tt : label $DB_ValX `t' } global DB_val`j' "`tt' " local i = `i' + 1 } end program define VLab1 global DB_Fh1 "Variable" global DB_Fh3 "Variable Label" if "$DBIsVar" != "1" { ClrBuf global DBIsVar 1 Draw1 1 exit } global DBIsVar 1 local t "$DB_VarX" if "`t'" == "" { local t "$DB_v1" } local i 0 while (`i' < $DB_NV1) & ("`done'" == "") { local i = `i' + 1 if index("${DB_v`i'}", trim("`t'")) == 1 { local done 1 } } if "`done'" == "" { window stopbox stop "Variable `t'" "not found" exit } Scroll `i'-$DB_Buf1 end program define VLab0 global DBIsVar 0 global DB_DBuf0 = $DB_DBuf ClrBuf global DB_Fh1 " " global DB_Fh3 "Numeric Value" Draw0 1 end program define List if "$DBIsVar" == "0" { lab `1' ${`2'} } end program define Save lab dat "$DB_DSL" end