SAS Team,
Good morning and happy Friday. I have a data set with dates that I want to change from character to numeric. I need some assistance since my code CREATED=input(Created_On,8.); changed character to numeric but did NOT transfer my date 9/17/2018. What am I missing from my code that is hindering my dates from transfering to my new column accordingly?
data work.PA_POC;
set POC_1."FORM RESPONSE"n;
/*place Created_On as numeric*/
CREATED=input(Created_On,8.);
/*******why isn't the dates moving to the new column *****************************/
run;
created_on created
9/17/18 .
9/20/18 .
1/1/19 .
There is no such thing as a numeric equivalent of the text string '9/17/18'. SAS does not know (and I do not know) how to turn this exact text string into a number, because it is not a number.
Now perhaps you wanted the text string '9/17/18' to be interpreted as the date September 17, 2018. Then you could use something like this code with a date/time informat to cause SAS to interpret the string as a date or datetime as appropriate.
data test;
y='9/17/18';
num_var=input(y,anydtdte.);
format num_var date9.;
run;
@lisa2002 If the solution worked for you, then please mark the post by @PaigeMiller as a solution. It might be helpful to others searching for similar problems.
when placing y='9/17/18'; how will it work if I multiple dates in the same row?
You just need to change the original code you wrote to use the ANYDTDTE informat in the INPUT function.
@lisa2002 wrote:
when placing y='9/17/18'; how will it work if I multiple dates in the same row?
Multiple dates where? Are you saying your character strings has multiple date values? Or that you have multiple character variables that each contain one date string?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.