\documentclass{article}
\usepackage{datatool}
%
\newcommand{\test}{}
%
\begin{document}
%
\DTLnewdb{mydata}%
%
\renewcommand{\test}{Doe}
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{Surname}{\test}%
%
\renewcommand{\test}{}
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{Surname}{\test}%
\end{document}
