

When you use a numeric variable in a string context, SAS will interpret it as a character value if it makes sense. You can use the PUT function with a SAS format to convert numeric values to character values. Luckily, I can use a concatenation function like CATS or CATX on it, and convert it to a character variable. In the above example, the INPUT function is used in combination with the w.d informat that converts the character value of TempCharacter to a numeric value and assigns the numeric value 98.6 to TemperatureNumber. a character variable to another character variable. Numeric to Character in SAS The Easy Way I have a numeric variable, but i want it to be character. The new variable will have numeric values without value labels. Variable conversions in SAS refer as to convert numeric to character variables or character to numeric variables. If we use the encode command, the new numeric variable will have value labels added to it.Īnother way of doing the same thing is by using the egen command, i.e.

Also note that our numeric variables representing dates (dob, startdate and enddate) are of different lengths: they are length 8 in STUDY2016 and length 4 in STUDY2017. Where oldvar is the name of the old variable and newvar is the name of the new variable. Let’s say we decide to make them of Character type. The commonest way to achieve this is probably by using the encode command, i.e.

In Stata, there are a few ways of converting string variables (with non-numeric values) to numeric variables (with numeric values). Stata recognizes these non-numeric values as “string” values, and their variables are called “string variables.” When analyzing data, it is often desirable to have numeric values (e.g., 0, 1, 2, 3, 4 or 1, 2, 3, 4, 5) instead of non-numeric ones. The number of columns (width) v of the output and the number of decimal places. Many survey questionnaires use a Likert or Likert-like scale, e.g.:īelow is another example of non-numeric values in a variable: There are two components in a SAS numeric format.
