About the SAS Program for This Example

Before performing an analysis, SAS programmers often must clean up the data. Often this cleanup includes converting character variables to numeric variables. For example, the data came from a vendor who used nonstandard character date values, and you need these values to be converted to SAS dates. Another example is when a colleague has a data set with a character variable that contains only digits, and you want to run a numeric analysis on that variable.
It is easy to write a SAS program to convert character variables to numeric variables. However, you want to give your colleague (who is not a SAS programmer) the ability to perform this conversion. You can create a SAS Studio task that enables anyone at your site to change a character variable to a numeric variable in any data set.
This document uses the Work.Character data set to show you how to create this SAS Studio task. Before you can continue, you must create this data set in SAS Studio. (For more information, see Create the Example Data Set.)
In the Work.Character data set, both Age and Enroll_Date are listed as character variables. However, you want Age to be a numeric variable and Enroll_Date to be a SAS date. A SAS date is a numeric variable that represents the number of days since January 1, 1960. SAS provides a variety of date formats that you can use to display these date values.
Contents of the Character Data Set
Here is a SAS program that you could use to convert the Enroll_Date variable:
data work.character_out;
   set work.character;
   new_enroll_date=input(enroll_date,ddmmyy10.);
run;
Note: The informat must match the current structure of the character variable. In this case, the character value 15/03/2015 corresponds to DDMMYY10.
Because you have had multiple requests for this type of conversion, you added macro variables to the SAS program. By using macro variables, you do not have to rewrite the program code for each user who needs to perform this conversion. Instead, the user can simply specify new values for the macro variables.
Here is the same SAS program using macro variables:
%let inlibname = work;
%let indsname = character;
%let invarname = date;
%let outdsname = character_out;
%let informat = ddmmyy10;

data &outlibname.&outdsname;
set &inlibname..&indsname;
&invarname._new = input(&invarname,&informat..);
run;
Because changing the values of the macro variables can be time-consuming, the remaining steps in this document show you how to convert this program to a SAS Studio task. The point-and-click interface enables users to quickly and efficiently customize their variables.