/***************************************************************************************************************** SAS file name: Convert_Numeric_to_Character.sas File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate the correct way of converting variables from numeric to character in SAS using the PUT Function. Author: Peter Clemmensen Creation Date: 02/09/2017 This program supports the blog post "Convert from Character to Numeric in SAS - The Easy and the Right Way" on SASnrd.com *****************************************************************************************************************/ /* From Numeric to Character */ /* Naive Approach */ data NumericToChar1; ZIP = 2100; /* Some number */ CharZIP = cats(ZIP); /* Naive conversion method */ put CharZIP=; /* Print to log */ run; ods select Variables; /* Select variable information */ proc contents data=NumericToChar1; run; /* Correct Approach */ data NumericToChar2; ZIP = 2100; /* Some number */ CharZIP = put(ZIP, 4.); /* Correct conversion method */ put CharZIP=; /* Print to log */ run; ods select Variables; /* Select variable information */ proc contents data=NumericToChar2; run;