I have a filed that will be 9 to 12 numbers in length, example 954265478. The field is in text format. I need to pad the front of this number with 0 to make the total length of the field 18, 000000000954265478. The length of my initial data wont always be 9, it can vary. Does anyone have a suggestion on how I can do this?
It would be more efficient to simply store a number as a number, and then associate an appropriate format for that number with it. A number is stored in binary, and in SAS, at present (per my understanding), consumes at most 8 bytes. Your 18 character text number consumes 18 bytes. All you need is a format associated with the number to make it report as 18 characters, padded with leading zeroes.
format number z18.;
attrib number format=z18. informat=18.;
both the format and attrib statements can associate the z18. format to a field.
then whenever SAS reports the value, it will print it as an 18 character ...
Using this method allows you to simply change the data representation with a format, as opposed to having to actually run through the data to change the textual representation.
Formats can even impose a picture to a number:
.ssn takes a 9 digit number and reports it as a social security number = 123-45-6789
you could create a credit card format that injects dashes or spaces into a 16 digit number.
Similarly informats can translate a textually entered "number" into a number.
(312) 555-1234 could be input directly and stored as a binary number = 3125551234, and then reprinted as a European style phone number = 312.555.1234
I would recommend reading the documentation for the format and attrib statements, and the proc format procedure.