Yes, but exercise caution and do the replacement over the course of weeks and/or months.
Sand traps a lot of detritus, and if it's sufficiently deep it can grow bacteria that produce hydrogen sulfide as a waste byproduct. In sufficient quantities, it can absolutely kill your tank. So we mitigate that by only removing a little sand at once, to limit the amount of sulfide that we can potentially release.
Each day, take out a cup or two of sand. What you do with it after you pull it out is up to you. Rinse your new sand thoroughly. Once you've removed enough of the old sand so that you can clearly tell the difference between new and old, put in some of the old sand, enough to replace what you took out. Rinse and repeat until most of the old sand is out.
I've done this myself. It is time-consuming and kind of irritating, but I've also done it quickly before. And that's how I know all about hydrogen sulfide.