BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pacman94
Calcite | Level 5

I have the following dataset where both 'Date' and 'Value' are in character format. I would like to convert Date from character to date field and Value from character to numeric using proc sql; command. I am unable to convert the Date

 

IDDateValue
12020-01-011
22020-04-012
32020-05-091
42020-09-041

 

proc sql;

create table test as

select ID, input(Date, mmddyy10.) as DateNew format=mmddyy10.,

input(Value, best.) as Value

from have;

quit;

 

the Value is being converted properly but not Date. It shows an error that invalid or missing/error

 

</>

Invalid date value

NOTE: Invalid argument to function INPUT. Missing values may be generated.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your strings are not in  Month Day Year order like you told the INPUT() function they were. 

Your strings are in Year Month Day order.

 input(Date, yymmdd10.) 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

When you have code that is causing an error, SHOW US THE LOG. The entire log for PROC SQL, every single word, in the sequence that it appears, with nothing chopped out. Please format the log properly by clicking on the </> icon and pasting the log as text into the window that appears; this makes the log more readable (and I no longer try to read logs that aren't formatted this way).

--
Paige Miller
pacman94
Calcite | Level 5

I edited the text

 

</>

Invalid date value

NOTE: Invalid argument to function INPUT. Missing values may be generated.

PaigeMiller
Diamond | Level 26

@pacman94 wrote:

I edited the text

 

</>

Invalid date value

NOTE: Invalid argument to function INPUT. Missing values may be generated.


This is not the ENTIRE log for PROC SQL that I asked for, and it needs to be formatted properly, as I described. What you have provided is part of the log, detached from the rest of the log and detached from the code that created the error, is not useful.

--
Paige Miller
Reeza
Super User
Show more of the log as it will contain the rest of the information.
Is it possible the dates are ddmmyy instead?
Or do you have missing dates or values? This code doesn't handle that case and that would generate the error you're seeing as well.

Your code is correct so this is a data specific issue.
pacman94
Calcite | Level 5

I see . the original dates are in YYYY-MM-DD format. I tried different combinations . There are no missing dates

Reeza
Super User
If the original dates are YYMMDD you need to use a YYMMDD informat, not a MMDDYY informat in your INPUT function.
Tom
Super User Tom
Super User

Your strings are not in  Month Day Year order like you told the INPUT() function they were. 

Your strings are in Year Month Day order.

 input(Date, yymmdd10.) 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1322 views
  • 2 likes
  • 4 in conversation