In SAS, all variables are either numeric or character. Character variables can consist of numbers, but they may be numbers that you wish to treat as characters. For example, Postcodes are numeric and ID variables are often numeric, but, in most cases, the numeric quality is not interesting.
- Skill level:
- Moderately Easy
Other People Are Reading
Create some character data. For example:
length x £6;
input x $ @@;
123 234 Robert
Here, the length statement makes the variable x a character variable of length 10. Note that 123 and 234 are being read as character.
Decide how many leading zeros you want to add. For example, you might want to add two zeros.
Add the zeros by concatenating them. In SAS, the concatenation operator is ||. On most keyboards, this is on the upper right, in the shift position of the \ character. For example:
y = '00'||x;
Check that it worked by printing the data.
proc print data = new;
Note that 00 is added to all cases.