datatool
has a macro called \DTLifinlist
which can check if an element is in the given comma-separated list, so this can be used when constructing a list of all the towns or ages, like this:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{datatool}
\begin{filecontents}{test.csv}
Name,Town,Age
Adam,Xcity,20
Berta,Ytown,30
Cesar,Ztington,40
Dora,Ztington,20
Emil,Ytown,30
Franz,Ytown,20
\end{filecontents}
\DTLloaddb{data}{test.csv}
\begin{document}
\newcommand*{\uniquetowns}{}
\newcommand*{\uniqueages}{}
\DTLforeach*{data}{\Town=Town,\Age=Age}{%
\expandafter\DTLifinlist\expandafter{\Town}{\uniquetowns}%
{}% do nothing, already in list
{% add to list
\ifdefempty{\uniquetowns}%
{\let\uniquetowns\Town}% first element of list
{% append to list
\eappto\uniquetowns{,\Town}%
}%
}%
% Similarly for age
\expandafter\DTLifinlist\expandafter{\Age}{\uniqueages}%
{}% do nothing, already in list
{% add to list
\ifdefempty{\uniqueages}%
{\let\uniqueages\Age}% first element of list
{% append to list
\eappto\uniqueages{,\Age}%
}%
}%
}
List of unique towns: \uniquetowns.
List of unique ages: \uniqueages.
\end{document}
Result: