/* Recall that there is a distinction between formats that read input data (informats) and those that write out data (formats). The following program gives an example of both. The comma6. informat is necessary because the values contain commas and SAS apparently does not like commas in numeric data. The dollar8. format writes out the price values with a dollar sign and the appropriate comma separators. */ filename foo URL "http://www.uvm.edu/~abh/stat295/datasets/cars.dat"; data cars; infile foo; input make :$11. model :$10. price comma6. est_mpg; run; proc print; title "Car prices with dollar format"; format price dollar8.; run; /* It is possible, and often desirable, to create your own formats so that instead of just a code being printed in your SAS output, text associated with that code is printed instead. For example, if your data include the value '1' to represent 'Male' and the value '2' to represent 'Female', it would be preferable to have the text printed in the output instead of the single digit codes which other people may not be able to decipher. SAS has a PROC FORMAT that lets you define your own format. This procedure is merely the means by which you create the format. It is used in the same way that a SAS-supplied format is used, that is, it must be associated with a variable by using a FORMAT statement. User-created formats can be saved permanently just like data sets. However, formats are stored in a format catalog. If you don't save the formats that you create, they must be recreated every time you want to use them. The following example creates a temporary format catalog. It is possible to use these formats within the same SAS program but if you want to use them in other programs, they should be saved in a permanent format catalog. */ proc format; value yesno 0="No" 1="Yes"; value likert 1="Strongly Disagree" 2="Disagree" 3="Neither agree nor disagree" 4="Agree" 5="Strongly agree"; value sexfmt 1="Male" 2="Female"; value edfmt 1="High school or less" 2="Some college" 3="College grad" 4="Grad school"; run; data test; input id sex education q1 q2 q3 q4 q5 q6 q7 q8 q9 q10; format sex sexfmt. education edfmt. q1 -- q5 yesno. q6 -- q10 likert. ; datalines; 01 1 2 0 1 1 0 1 4 2 3 2 5 02 2 3 1 1 0 0 0 3 2 1 1 2 03 2 4 0 1 0 1 1 4 3 2 4 3 04 2 3 1 0 0 1 1 4 5 3 4 2 05 1 1 1 0 1 0 1 3 2 1 3 2 06 1 4 1 1 1 1 0 2 3 2 1 4 07 2 4 1 1 0 0 1 4 5 4 3 4 08 2 1 1 0 0 0 1 2 3 4 3 2 09 1 2 0 1 0 1 0 3 2 4 5 3 10 1 1 0 1 1 0 0 2 3 1 2 3 ; run; proc freq data=test; table sex -- q10; title "Test of temporary formats"; run; /* Now let's run the same PROC FORMAT, but save the formats in a permanent format catalog. We define a SAS library, just as we have done previously to store permanent SAS data sets. To have the PROC FORMAT store our formats in the appropriate library, we use the library= option on the proc format statement. SAS will always look for formats in the WORK library or in a SAS library called LIBRARY. If you are going to store and use your own formats, it is good practice to always define a SAS library called LIBRARY. */ libname library "Z:\sasformats"; proc format library=library; value yesno 0="No" 1="Yes"; value likert 1="Strongly Disagree" 2="Disagree" 3="Neither agree nor disagree" 4="Agree" 5="Strongly agree"; value sexfmt 1="Male" 2="Female"; value edfmt 1="High school or less" 2="Some college" 3="College grad" 4="Grad school"; run;