![]() We can see that the new variable we created, char_day, is a character variable. ![]() ![]() In the PUT () function, the format must be the same type as the source. It will also write a note to the SAS log, saying that numeric values have been converted to character values, which is something which should always be avoided you should want to be in control of when numeric values are converted to characters, and not leave this to SAS. The format tells SAS how to output or store the data. newvarchar PUT (oldvarnum, format) The PUT () function is similar to writing out data using the PUT statement. The DATA step, PROC SQL, and the SAS macro language are used to. We can use proc contents once again to check the data type of each variable in the new dataset: /*display data type for each variable in new dataset*/ To convert a numeric variable to a character variable, you use the PUT () function (which uses formats). This paper shows how to convert character variables that store numbers to numeric variables. Note: We used the drop function to drop the original day variable from the dataset. SAS Interface to Application Response Measurement (ARM) Security. This sample shows how to convert all character variables to numeric while excluding one character variable and keeping the same variable names in the output data set. We can use the following code to create a new dataset in which we convert the day variable from numeric to character: /*create new dataset where 'day' is character*/ We can see that day and sales are both numeric variables. This function uses the following basic syntax: charactervar put(numericvar, 8. We can use proc contents to view the data type of each variable in the dataset: /*display data type for each variable*/ proc contents data=original_data You can use the put() function in SAS to convert a numeric variable to a character variable. Suppose we have the following dataset in SAS that shows the total sales made by some store during 10 consecutive days: /*create dataset*/ Related: How to Convert Character Variable to Numeric in SAS Example: Convert Numeric Variable to Character in SAS The following example shows how to use this function in practice. This function uses the following basic syntax: character_var = put(numeric_var, 8.) When presented with this code, SAS first converts the value of id from character to numeric and then compares the resulting value to the numeric constant 2. We can use the following code to create a new dataset in which we convert the day variable from numeric to character: /create new dataset where 'day' is character/ data newdata set originaldata charday put(day, 8.) drop day run /view new dataset/ proc print datanewdata. You can use the put() function in SAS to convert a numeric variable to a character variable. where we are instructing SAS to compare the value of a character variable to a numeric constant. We can see that day and sales are both numeric variables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |