/***************************************************************************************************************** SAS file name: proc_format File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to use PROC FORMAT to write user defined formats. Author: Peter Clemmensen Creation Date: 18/01/2019 This program supports the example page "Writing User Defined Formats in SAS with PROC FORMAT" on SASnrd.com *****************************************************************************************************************/ /* A naive if then else approach to clasify numeric ranges */ data test1; set sashelp.baseball; if salary = . then incomeclass="N/A"; else if salary < 500 then incomeclass="Low"; else if 500 <= salary < 1500 then incomeclass="Middle"; else if salary >=1500 then incomeclass="High"; run; /* Binning ranges with PROC FORMAT */ proc format; value income low -< 500 = "Low" 500 -< 1500 = "Middle" 1500 - high = "High" . = "Missing"; run; /* Use income format to classify income class in a new data set with the PUT Function */ data test2; set sashelp.baseball; incomeclass=put(salary, income.); run; /* Use income format to bin salary classes in PROC FREQ */ proc freq data=sashelp.baseball; tables salary; format salary income.; run; /* A picture format example */ proc format; picture dollarsal low-high='000,000,000' (mult=1e3 prefix='$'); run; /* Use the dollarsal picture format in PROC PRINT */ proc print data=sashelp.baseball(obs=10); format salary dollarsal.; var name team salary; run;