
* Example 8: Numeric to character with left alignment using DATALINES to read in */ * Example 7: Numeric to character and end up with the original variable name */ * Example 6: Convert a character datetime to a SAS datetime */ * For more information, see the Statements Reference documentation.*/ * name from the RENAME which is Orig_var. * the created variable), but the resulting output has the format inherited by the new */ That is why you see the FORMAT on New_var (the initial variable name for */ During the current DATA step, you use the old variable name in programming */ * The RENAME statement affects the name in the output data set, not during the current */ * Format it to look the same as the original. * Example 5b: Same as 5a but ends up with the same name for the resulting variable.*/ * variable and format it to look the same as the original value.


* Example 5a: Convert a character time value to a SAS time */ * I have chosen to format the resulting SAS date with the DATE9. * documentation, I see that the structure mm-dd-yyyy is read by the MMDDYY10. * Example 4: Convert a character date to a SAS date. * The result has a standard numeric missing value of. * Example 3: Multiple input values with a blank character value for one of the values. * You can comment out the FORMAT statements to see what the unformatted value looks like. * Example 2a and 2b: Character to numeric with additional characters in original string */ * the original name, uncomment the DROP and RENAME statements. If you want the result to have just one variable with */ * The resulting data set has both the original character variable and a new */ * Example 1: The simplest case character to numeric */
Numeric to character sas how to#
The examples below range from simple to more complex.īe sure to run PROC CONTENTS periodically to see the changes that are made to the variables.Įxample 9 contains the code for "Putting it all together".Įxamples 10 and 11 show how to perform these actions on a variable in a data set. In addition, SAS Institute will provide no support for the materials contained herein. Not be liable for any damages whatsoever arising out of their use of this material. Recipients acknowledge and agree that SAS Institute shall "as is" without warranty of any kind, either express or implied, includingīut not limited to the implied warranties of merchantability and fitness for a These sample files and code examples are provided by SAS Institute
Numeric to character sas full#
How do you convert a numeric value to a SAS date?Ĭlick the Full Code tab to see the solution for this question and many more examples.įor even more information about converting values, see the following SAS tutorial video: You want it to be a SAS date with a format that displays the value as 10122012. This looks like a SAS date, but when you use PROC CONTENTS, you see that there is no format applied, so it is actually the integer value 10122012.

Start with a numeric variable with a value of 10122012 as an example. Both of these steps are needed to convert a numeric value that looks like mmddyyyy but is not a SAS date, to a SAS date.

You have seen how to convert numeric values to character and character values to numeric. The end result is a SAS date that looks the same as the original variable, but can be analyzed and manipulated by the date functions:Ĭhar_var = put(num_var, 10. The following code starts with a character string "12JUL2016", creates a SAS date, and then formats it with the DATE9. reads date values in the form ddmmmyy, which matches 12JUL2016. Look at the date informats to determine which informat matches your values. If it is a character variable, you can convert it to a SAS date so that you can take advantage of the SAS date functions. Is Startdate a character string "12JUL2016" or is it a numeric variable with a format applied? You can use PROC CONTENTS to verify the variable type and to see whether a format has been applied to it. A SAS date might be formatted so that it contains characters in the display, but it is always stored as a numeric variable.įor example, suppose you receive a data set that contains a variable named Startdate that is displayed in PROC PRINT output as 12JUL2016. Run Using the INPUT function to convert a character date to a SAS dateĪ SAS date is a numeric value with which you can use date functions and calculations.
