BookmarkSubscribeRSS Feed
lisa2002
Fluorite | Level 6

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                                     .

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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;

  

--
Paige Miller
lisa2002
Fluorite | Level 6
Thank you for explaining this to me. The code definitely worked.
koyelghosh
Lapis Lazuli | Level 10

@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.

lisa2002
Fluorite | Level 6

when placing  y='9/17/18'; how will it work if I multiple dates in the same row? 

PaigeMiller
Diamond | Level 26

You just need to change the original code you wrote to use the ANYDTDTE informat in the INPUT function.

--
Paige Miller
Tom
Super User Tom
Super User

@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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 1035 views
  • 1 like
  • 4 in conversation