In some cases, an endoscopy procedure can be used to treat diseases. For instance, if cancerous growths are found, the doctor can take them out for further examination. This is called a biopsy. Biopsies are also done to test for certain bacteria that cause ulcers.