Identification of priority populations such as men who have sex with men (MSM) is important in surveillance systems to monitor trends of sexually transmitted infections (STIs). We explored using routinely collected non-behavioural data as a means to establish MSM status in surveillance by assessing anorectal swab as a marker of male-to-male sexual exposure. We used chlamydia testing data from a sexual health clinic, 2007–2012. Men reporting any male sexual partner(s) in the previous 12 months were considered MSM. The dataset was split into development and validation samples to develop a univariate predictive model and assess the model fit. The dataset included 30 358 individual men and 48 554 episodes of STI testing; 45% were among reported MSM and an anorectal swab was performed in 40% of testing episodes. Anorectal swabbing had good diagnostic performance as a marker for MSM status (sensitivity = 87%, specificity = 99%, positive predictive value = 98·6%, negative predictive value = 90·3%). The model showed good fit against the internal validation sample (area under the curve = 0·93). Anorectal swabs are a valid marker of MSM behaviour in surveillance data from sexual health clinics, and they are likely to be particularly useful for monitoring STI trends among MSM with higher risk behaviour.