Background: Medications to prevent and treat SARS-CoV-2 infection are needed to complement emerging vaccinations. Recent in vitro and electronic health record (EHR) studies suggested that certain allergy medications could prevent SARS-CoV-2 infection. We sought to carefully examine the potential selection bias associated with utilizing EHRs in these settings. Methods: We analyzed associations of three allergy medications (cetirizine, diphenhydramine or hydroxyzine) with testing negative for SARS-CoV-2, measuring the potential effect of selection bias on these associations. We used a retrospective cohort of EHR data from 230,376 patients (18 years+) who visited outpatient clinicians in a single, large academic center at least once but were never hospitalized (10/1/2019À6/1/2020). Main exposures included EHR documentation of three allergy medications and allergy, with an intermediate outcome of receipt of a SARS-CoV-2 test, and the primary outcome as testing negative. Findings: SARS-CoV-2 testing rates varied by sex, age, race/ethnicity and insurance. Increasing age and public insurance were associated with a higher adjusted odds of test negativity, while being Black or Hispanic was significantly associated with test positivity. Allergy diagnosis and use of any of three allergy medications were each associated with a higher likelihood of receiving a test (e.g. diphenhydramine -Odds Ratio (OR) 2.99, 95% Confidence Interval (CI) 2.73, 3.28; cetirizine 1.75 (95% CI 1.60, 1.92)). Among those tested, only use of diphenhydramine was associated with a negative SARS-CoV-2 test (adjusted OR = 2.23, 95% CI 1.10, 4.55). However, analyses revealed that selection bias may be responsible for the apparent protective effect of diphenhydramine. Interpretation: Diphenhydramine use was associated with more SARS-CoV-2 testing and subsequent higher odds for negative tests. While EHR-based observational studies can inform a need for interventional trials, this study revealed limitations of EHR data. The finding that diphenhydramine documentation conferred a higher odds of testing negative for SARS-CoV-2 must be interpreted with caution due to probable selection bias.