Let x be the number of cards he had at first.
He bought 9 new cards:
x + 9
His dog ate half (Which means he also had half left)
0.5(x+9)
There are 38 cards left:
0.5(x+9) = 38
0.5x + 4.5 = 38
0.5x = 38 - 4.5
0.5x = 33.5
x = 33.5 ÷ 0.5
x = 67
So Sam had 67 cards to start off with.
Note: You may want to write 0.5 as half (1/2) .. it is just clumsy to type that, so I kept it as decimal.