Catalyzes the methylation of sarcosine and dimethylglycine to dimethylglycine and betaine, respectively, with S-adenosylmethionine (AdoMet) acting as the methyl donor. It has strict specificity for sarcosine and dimethylglycine as the methyl group acceptors. 2 S-adenosyl-L-methionine + sarcosine = glycine betaine + 2 H(+) + 2 S-adenosyl-L-homocysteine p-chloromercuribenzoate acid inhibits 23% of the SDMT activities on sarcosine and dimethylglycine, and S-adenosylhomocysteine (AdoHcy) inhibits completely GSMT activities. Optimum pH is around 8 and 7.6 for sarcosine and dimethylglycine, respectively. The pH optimum appears to depend on the buffer used. 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.