

As the horsepower values all have three digits, we specify a format of 3., which means that the value of horsepower is written as a character string of three digits in the concatenation. The second argument of the PUT functions allows you to specify the format that should be used during the conversion. Type_horse = STRIP(type)!!"-"!!PUT(horsepower,3.) This issue can be avoided by first using the PUT function to convert the values from numeric to character. By default, SAS uses a format of BEST12, since our horsepower values each contains three digits, it means that SAS pads the values with nine leading spaces when performing the concatenation. When SAS performs this implicit numeric to character conversion it must select the format to use when performing the conversion and the width of the converted string. These leading spaces are created by the implicit data conversion. Note how instead of being concatenated directly onto the hyphen, the horsepower, there are many leading spaces prior to the digits. However, printing the dataset shows why this approach can be dangerous, as shown below.
#As numeric code#
In our case, the concatenation function (!!) expects a character variable, however horespower is numeric.Īs the output dataset has been created, it may be tempting to leave the code as is, and have SAS perform the conversion for you. This tells us that the code in line 45 of the log, at column 34 numeric variable has been used where a character variable was expected. NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 43 DATA cars Ĥ5 type_horse = STRIP(type)!!"-"!!horsepower The output is created however the log displays the following message.


Type_horse = STRIP(type)!!"-"!!horsepower Implicit conversions also take more CPU time than explicit conversions and so may cause your program to execute more slowly.Ĭonsider the following example, where we try to concatenate the character variable type with the numeric variable horsepower. It is possible to rely on SAS to perform these conversions imlpicitly, however, in general this is not considered good programming practice and it is usually preferable to perform these conversions explicitly. Since WebSgml, XML and HTML 4, the code points of the Universal Character Set (UCS) of Unicode are used. In a similar way to character to numeric implicit conversions, this message occurs when you try to use a numeric variable in a function that requires a character argument, or to assign a numeric value to a variable which has already been defined as numeric. A numeric character reference (NCR) is a common markup construct used in SGML and SGML-derived markup languages such as HTML and XML.It consists of a short sequence of characters that, in turn, represents a single character.
#As numeric how to#
Here we look at what causes numeric to character implicit conversions and how to avoid them In the last post SAS tips & tricks #7 we looked at how to avoid implicit character to numeric conversion. It creates a double-precision vector of the specified length with each element equal to 0.
