In sam, g has two uses - either as a guard or after an s command where all substitutions are made

Quoting sam(1) (available at <http://9p.io/magic/man2html/1/sam>)
after an s command:
If the command is followed by a g, as in
               s/x/y/g, all matches in the range are substituted.
as a guard:
g/regexp/ command
v/regexp/ command
               If the range contains (g) or does not contain (v) a
               match for the expression, set dot to the range and run
               the command.