The 19-year-old student has apologised for his actions after being handed the ban following an International Rugby Board hearing during which he admitted using a pill called Pro-SD.
Chalmers tested positive for methandienone and stanozolol, which are both listed as anabolic androgenic steroids in the list of prohibited substances by the World Anti-Doping Authority, while on duty with the Scotland Under-20s squad ahead of a Test with Ireland back in May.
The match was a warm-up for the Junior World Cup in France and Chalmers did not play in the tournament, while he has also not featured in any of Melrose's' three Scottish Premiership fixtures so far.
In a statement, he said: "First of all I would like to apologise to my club Melrose RFC, my team-mates, the Scottish Rugby Union, my friends and my family.
"I am disappointed in myself and have to take personal responsibility for this incident which has ultimately led me to being banned from the game I have grown up with and love so much.
"I have been stupid, naive and impressionable and would urge other young players not to give in to the constant pressure to be bigger in the manner that I did over a two-week period in April last season.
"After my experience I would certainly encourage young players to seek out the correct advice from the right places before taking any kind of supplement or product.
"I hope over time I can be forgiven for my mistake and I can come back to compete in the game I love so much."
Chalmers earlier told the IRB his actions were "stupid, naive (and) desperate".
He added in his evidence: "I totally regret my actions. I am mortified and embarrassed with the whole situation and feel I have not only let myself down but my club and family as well."
An IRB Board judicial committee gave Chalmers credit for his offer to participate in an anti-doping education programme.
But it added in its written judgement: "However, his experience is a salutary warning to any person tempted to take what is sometimes described as a 'short cut'. The only thing cut short is this young man's rugby career."
The committee added: "On his own account he took Pro-SD thinking it was a 'testosterone pill' in the hope it would help him gain weight.
"He carried out no research or advice and accepted the risks in doing so. He was entirely at fault and, as he candidly accepted, he accepts the consequences."
The Scottish Rugby Union's head of regulation, Graham Ireland, said: "Scottish Rugby takes a very clear stance on anti-doping and we have a zero-tolerance policy on doping offences in Scotland.
"We are committed to keeping the game in Scotland clean through a programme of robust drugs-testing coupled with education on the dangers of illegal substances.
"Scottish Rugby, working in partnership with anti-doping agencies and other governing bodies, undertakes a programme of drugs-testing after-matches, after training, out of competition and at home.
"Testing can occur at any level of the game, anywhere and at any time.
"Since the 2009-2010 season there have been around 800 drugs tests in Scottish Rugby, at all levels of the game, and, in that period, there have now been two adverse findings - an amateur club player in 2010 who was found to have taken a slimming product that contained an illegal substance and this latest case, involving a club player who took a product because he naively thought it could help him to put on weight.
"We are continuing to work diligently to ensure the importance of a drugs-free game is understood by all involved in the sport in Scotland."
Chalmers' father, who coached Melrose last season and is now backs coach at Esher, vowed to stand by his son but warned of the dangers of supplements.
The 60-times capped Scot said: "Sam has made a huge mistake, but anyone that knows him will tell you what a pleasant, polite young man he is.
"I must point out that Sam's family in no way condone what he has done, but we will be there to support and help him through this difficult time.
"Sam is a competitive, ambitious and hard-working young man who now faces the biggest challenge of his life.
"I believe the lessons Sam has learned from this experience will only make him stronger and when he does return to rugby you will see a player who has matured.
"My message to young players would be not to take any short cuts. These products may not only damage your career, but they can also damage your health. Get the right advice from the right people before you take any product or supplement."