Here is an easy way for you to make it working although you need to enhance your codes with the use of 'IF' and 'AND' functions to get sure the inputs from the users are correct then process to next step.
Don't forget to localize the variable 'lay' as in the following codes.
(setq LINELAYER (getvar "clayer"))
(if (tblsearch "LAYER" (setq lay (strcat LINELAYER "-txt")))
(progn
(setvar "clayer" lay)
(command "mleader" COORD TEXT ANS)
(setvar "clayer" LINELAYER)
)
(alert (strcat "layer name < " lay " > is unavailable in this drawing "))
)