I get an error sed: 1: "1~2d": invalid command code ~ when I use sed '1~2d' sample.txt
An adress like 1~2 is a GNU extension, it's not available in the BSD sed which is part of macOS.
The probably easiest way out of this is to install GNU sed with
brew install gnu-sed

and then run gsed '1~2d' sample.txt.
If you don't want to install additional software see https://stackoverflow.com/questions/2560411/how-to-remove-every-other-line-with-sed for alternative approaches.