I have 2 Macs (one MacBook Pro and one iMac). I made a copy of the installer on a USB drive and then installed El Capitan on MacBook Pro. Now I want to use the drive to install El Capitan on the iMac. How can I do it without losing my data on iMac?
If you already have an older version of OS X installed on your iMac just go to the App Store, search for El Capitan and click install. It will update to the latest version and your data will stay on the iMac.
If you don't have an OS installed on the iMac, but have a Time Machine backup of your data, just boot from the El Capitan USB stick and do a fresh install. At the beginning of the process it will ask you if you want to transfer your old data from a Time Machine backup. Use that option and it will create a new OS X installation with your old data in place.
If you don't have any OS installed on the Mac (but still have data on it) and no external backup of your data, then you should first create such a backup to an external drive, then install El Capitan using the USB stick and then copy the data back from your external backup to your iMac.
If you have a copy of your data on your Macbook, you could also transfer everything using a direct connection cable between the iMac and the Macbook. Read here how to do it: https://support.apple.com/en-us/HT204350
Always have a backup first. If you proceed, just know data loss is real (but not expected result). You can select the OSX installer from your desktop/Finder and install in place (be sure the USB is plugged in). Installing the OS this way will not overwrite your data.
You just need to go to "upgrade" instead of "install" in the main installation window. Of course is highly recommended to backup your data before, if the upgrade fails, you will have to format and install (happened to me).
Also you can clone or backup with Time Machine, do a "fresh install" (formatting the HDD) and use the Migration Assistant to recover your personal data.