Catalyzes the methylation of sarcosine and dimethylglycine to dimethylglycine and betaine, respectively, with S-adenosylmethionine (AdoMet) acting as the methyl donor. 2 S-adenosyl-L-methionine + sarcosine = glycine betaine + 2 H(+) + 2 S-adenosyl-L-homocysteine Inhibited by n-butylic acid and S-adenosyl-L-homocysteine. Optimum pH is 8.8. The activities remain high at more alkaline pH but decrease sharply at the acidic side of the optimal pH. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 2/3. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 3/3. Monomer. Belongs to the methyltransferase superfamily.