If informats instruct SAS how to read in variables, think of formats as instructions on how to display them. To tell SAS how to display a variable, use the FORMAT statement, followed by the variable name, and finally the format. There’s many different formats available, but one of the most commonly used ones is the $ sign for character variables. The general syntax for it is a dollar sign followed by the number of characters you wish to display, and a period to finish it off.
Given the code below, what would the output look like?
INPUT Names $ Age;
FORMAT Names $2.;
a) . 23
b) Jess 23
c) Je 23
Remember, the format statement only tells SAS how to display the values. In this case, we used the format “$2.” so SAS only returned the first 2 characters, but Jess’ full name, with all 4 characters, is actually what’s saved in the table. Try re-running the code with the format “$4.” to see what it does.