# SAS: How to Convert Numeric Variable to Character

You can use the put() function in SAS to convert a numeric variable to a character variable.

This function uses the following basic syntax:

```character_var = put(numeric_var, 8.);
```

The following example shows how to use this function in practice.

### Example: Convert Numeric Variable to Character in SAS

Suppose we have the following dataset in SAS that shows the total sales made by some store during 10 consecutive days:

```/*create dataset*/
data original_data;
input day sales;
datalines;
1 7
2 12
3 15
4 14
5 13
6 11
7 10
8 16
9 18
10 24
;
run;

/*view dataset*/
proc print data=original_data;
```

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;
```

We can see that day and sales are both numeric variables.

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 new_data;
set original_data;
char_day = put(day, 8.);
drop day;
run;

/*view new dataset*/
proc print data=new_data; ```

Note: We used the drop function to drop the original day variable from the dataset.

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*/
proc contents data=new_data;```

We can see that the new variable we created, char_day, is a character variable.

The following tutorials explain how to perform other common tasks in SAS:

May 29, 2024
May 13, 2024
April 25, 2024

## One Reply to “SAS: How to Convert Numeric Variable to Character”

1. gabriel says:

After converting, I’m having problems with blancks at the left side of the number.
Dont know how to solve…

ex>
number
11
1

new colum (caract)
11
1

this space are making troubles. Anybody know how to substitute blacks for zeros?