BookmarkSubscribeRSS Feed
ari
Quartz | Level 8 ari
Quartz | Level 8

I am trying to read a date column in sas from csv file but it gives some error:

 

error: NOTE: Invalid argument to function INPUT at line 2134 column 11

 

Appreciate  any help to resolve this issue. Thanks

 

data:

have:

id   date

1    27-Apr-12

2    03APR2013

3    11-Mar-13

4   01-Jun-12

my code:

data want;
set have;
format date date9.;
date=upcase(date);

if not missing(date) then do;
lbdt=input(date, ddmmyy9.);
end;

run;

 

7 REPLIES 7
LinusH
Tourmaline | Level 20
Yeah, your format doesn't match your date on every observation.
Otherwise sure, anydt might work (as a last resort - try to get clean data from your supplier is the no 1 option).
Data never sleeps
ari
Quartz | Level 8 ari
Quartz | Level 8
thanks LinusH
PGStats
Opal | Level 21

SAS offers generic date formats such as ANYDTDTE. to handle this kind of poor quality data. Try:

 

data have;
input id   date :$20.;
datalines;
1    27-Apr-12
2    03APR2013
3    11-Mar-13
4   01-Jun-12
;

data want;
set have;
d = input(date, ?? anydtdte.);
format d yymmdd10.;
drop date;
rename d=date;
run;

proc print; run;
PG
ari
Quartz | Level 8 ari
Quartz | Level 8
thanks PG
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Simple answer, clean your data.  27-Apr-12 is not the same as 27APR2012 or in fact 20120427.  What if you have dates in US format:

02012012 - is this 02Jan or 01Feb?  Garbage data will 90% of the time yield garbage results.

 

And a secondary note, CSV is not Excel, CSV=Comam Separated Variable file, which is a plain text file with commas separating data elements.  The fact that Excel has a parser for that doesn't make it an Excel file.

Ksharp
Super User
data have;
input id   date : date11.;
format date date9.;
datalines;
1    27-Apr-12
2    03APR2013
3    11-Mar-13
4   01-Jun-12
;
run;
ari
Quartz | Level 8 ari
Quartz | Level 8
Thanks Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1419 views
  • 4 likes
  • 5 in conversation