There are several software you can use. R, PLINK, and PHASE are the most comprehensive ones. However, if you don't have experience working with them, I recommend using Haploview which is easy to use and has graphical interface. By reading the guideline provided in the software, you can prepare the input file with ease!
Unfortunately there is no specific written code for everyone, however you may find some great sample codes on the internet that you could manipulate based on your requirments. I suggest searching for keyword "haplotype" in "cran.r-project.org" and "bioconductor.org" which may help you find your desirable package, cause there are lots of various packages for analyzing genotypic/haplotype data.
I have used different packages among them "snpStats" was the best one. You can easily use "ld" function of the package and get the measure of LD of your SNPs. Also, there are other packages like LDlinkR, pegas, haplotypes, haplo.stats, etc which you may use.
Before start using any packages, you must read the documentation accompanied by them. It has all the things you need to start and perform your analysis completely. In case of any confusion, look up your question in "stackoverflow", I am confident you'll find your answer there and will be able to analyze your data easily and precisely.
To me, Haploview software is very easy to SNP analysis. Only thing you have to do is to enter data correctly in the software or prepare first an excel file in a appropriate manner then load it into the software.