DATA Step, Macro, Functions and more

convert text to numeric date function

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

convert text to numeric date function

 

I want to convert the datereturned field from text to number type ( to mmddyy10. Format). It has length $ 10. and format $10.I have tried the below SAS code and it doesn’t work.

Still it display as Text instead of number and values shows as .

 

 

 data want;

set have;

length _ datereturned $10.;

_datereturned =input(datereturned,mmddyy10.);

put _datereturned = date9.;

run;

 

Thanks in Advance


Accepted Solutions
Solution
‎04-13-2016 11:42 PM
Super User
Posts: 17,784

Re: convert text to numeric date function

It's the missing that's generating the errors? check against the row number in log vs data.

and try the following:

 

input(datereturned, ?? mmddyy10.);

View solution in original post


All Replies
Super User
Posts: 17,784

Re: convert text to numeric date function

You've declared the variable character in your length statement first.

 

length _ datereturned $10.;

 

Try removing that line and see what you get.

Contributor
Posts: 30

Re: convert text to numeric date function

Hi Reeza,

 

It doesn't work.

 

Error message:

NOTE: Invalid argument to function INPUT at line 22 column 21.

WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.

 

Super User
Posts: 17,784

Re: convert text to numeric date function

What does your field currently look like? Do you have missing?

 

Post the full log with the error message so that we can see what's causing the error.

Contributor
Posts: 30

Re: convert text to numeric date function

Hi Reeza,

 

Yes the field has missing values

 

Attached the screen shot for your reference.

Solution
‎04-13-2016 11:42 PM
Super User
Posts: 17,784

Re: convert text to numeric date function

It's the missing that's generating the errors? check against the row number in log vs data.

and try the following:

 

input(datereturned, ?? mmddyy10.);

Super User
Posts: 9,676

Re: convert text to numeric date function

length _datereturned $10.;

 

Why do you define _datereturned as character variable, since you want it be numeric. 

Remove this statement.

Contributor
Posts: 30

Re: convert text to numeric date function

[ Edited ]

Tried the below code and it worked well

 

data want (drop=LAST_SURVEY_DATE1);
set have;
format LAST_SURVEY_DATE mmddyy10.;
LAST_SURVEY_DATE = input(LAST_SURVEY_DATE1, ?? yymmdd10.);
run;

 

 

Thanks for all your responses.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 547 views
  • 2 likes
  • 3 in conversation