Your best bet is to cast on more than 17–maybe 25. This way you can measure and count your stitches without having to include the edge ones.
The goal of a gauge swatch is not to make a square 4 x 4, but rather to make a square that’s larger so you can see how many real stitches you get over 4 inches.
The stitches across are more important than the rows in length. You usually knit for X number of inches rather than a set number of rows. You can knit more or fewer rows to get the length you want, but you can’t adjust for width once you’ve started.