Remember that internally, SAS will NOT store a leading zero as part of a numeric variable, so you only need to use the z4. format for display of the leading zero. So in my code below, you can display the numeric patient id either with the best4. format (no leading zeros) or with the z4. format (display leading zero). To turn a CHARACTER patient ID into a NUMERIC patient ID, you need to use the INPUT function.
To "prepend" a zero onto a character variable, you could use the technique that you originally showed, but your patient id will remain character.
IF patient ID is already NUMERIC, then you can turn it into a CHARACTER string with a leading zero using the PUT function.
But it sounded to me like your patient ID was already character and you wanted it to be numeric and that will take the INPUT function. But, that also requires that you use the Z4. format in order to display patient id once it is a number. See the attached code.
*** the code;
input charpat $ numpat;
** convert charpat to new numeric var;
newnumpat1 = input(charpat,4.);
** convert numpat to new character var;
newcharpat1 = put(numpat,z4.);
** use concat to put zero onto char patient id;
** but patient id remains character;
newcharpat2 = '0'||trim(charpat);