According to a synopsis on IMDB...he has the numbers but guesses the order.
Over the next few days Ray takes note of the guards' routines. At least once a day the two guards who monitor the isolation area leave their post for a seven minute smoke break. The guards bring Ray his lunch which consists of, most importantly, a carton of chocolate milk. He dissects the cardboard milk carton and extracts a transparent plastic sheet from the label. The following day, when he's escorted out of his cell, he secretly applies the plastic film over the keypad which accesses his cell. The guard punches in the 4-digit access code, leaving his fingerprints on the film. Ray sneaks the film from the keypad, stuffs it in the bible, guesses the access code from the fingerprints and waits for the right moment to escape.
The actual dialogue is..
With the four numbers it's just a numbers game to identify the correct sequence.
There also an indication that he at least gets a glance at the keypad as the numbers are being identified.

If he has, say, the last two then his odds of getting it right first time are only 50/50.
Additionally, we only see the successful attempt...it doesn't necessarily mean there was only one...he states that he was unobserved for 7 minutes every day. So he had an opportunity to test other combinations.