The present invention relates to a process for preparing a macrocyclic ligand and for producing a pharmaceutical liquid formulation comprising a complex of said ligand with a lanthanide or similar compounds. The macrocyclic ligand of the present invention is a derivative of tetraaza macrocycles such as 1,4,7,10-tetraazacyclododecane (cyclen), 1,4,7,10-tetrazacyclotridecan (homocyclen) and 1,4,8,11-tetraazacyclotetradecane (cyclam), such as DOTA, TRITA, TETA, DOTMA, TCE-DOTA, DOTA-pNB, D03A, HP-D03A, D03A-butrol, D03MA, ODOTRA, D03A-L2, DOTP, DOTMP, DO2a, THP, THED, DOTAM, DOTTA. The preferred lanthanide and similar compounds are Gadolinium (Gd), Yttrium (Y) and Terbium (Tb). The process of the present invention aims to obtain an accurate balance between the ligand and the lanthanide, and to avoid the presence of free lanthanide in said formulation, by calculating the necessary amount of ligand for a formulation batch, measuring the moisture content of a sample of the material in said batch, calculating the total amount of moisture present of the batch and calculating the total amount of material which is required to prepare the batch size. In this way, the production of a pharmaceutical liquid formulation comprising a complex of a macrocyclic ligand with lanthanide is more accurate, faster and easier. The present invention is thus useful for the production of pharmaceutical liquid formulations comprising a complex of a macrocyclic ligand with a lanthanide, which can be used as contrast agents for magnetic resonance imaging.