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

I am trying to import a csv file using the code below, however, for the date column SAS is giving me the NOTE: Invalid data for Date in line 2 40-48. And it also says DOB=. _ERROR_=1 _N_=1

 

data BH;

infile 'C:\desktop\NewDemo\apeal2.csv' dsd firstobs=2 truncover;

length ID 8 Race $32. Ethnicity $32 Gender $20;

input ID Race Ethnicity Gender Date;

format Date date9.;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Add a delimiter to the INFILE statement, and the proper informat:

data BH;
infile
  'C:\desktop\NewDemo\apeal2.csv'
  dlm=','
  dsd
  firstobs=2
  truncover
;
length ID 8 RACE $32 ETHNICITY $40 Gender $20 date 4;
input ID RACE ETHNICITY Gender Date :mmddyy10.;
format Date mmddyy10.;
run;

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

There is no variable DOB in the code you posted, so the log message cannot be from that step.

Please post the complete log from the failing step; use this button to post the log:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Yughaber
Quartz | Level 8
I am sorry but I don't have/see that </> in my toolbar


237 data BH;
238 infile 'C:\desktop\NewDemo\apeal2.csv' dsd firstobs=2 truncover
238! firstobs=2 truncover;
239 length ID 8 RACE $32 ETHNICITY $40 Gender $20;
240 input ID RACE ETHNICITY Gender Date;
241 format Date mmddyy10.;
242 run;

NOTE: The infile
'C:\desktop\NewDemo\apeal2.csv' is:
Filename= C:\desktop\NewDemo\apeal2.csv,
RECFM=V,LRECL=35677,File Size (bytes)=18522591,
Last Modified=19Oct2020:22:08:43,
Create Time=18Oct2020:00:57:44

NOTE: Invalid data for Date in line 2 50-58.
RULE: ----+----1----+----2----+----3----+----4----+----5----
2 333333333,Other,Hispanic or Latino,Male,6/20/
55 1953 58
ID=333333333 RACE=Other ETHNICITY=Hispanic or Latino
Gender=Male Date=. _ERROR_=1 _N_=1
NOTE: Invalid data for Date in line 3 54-61.
3 333333333,Asian,Non Hispanic or Latino,Male,3
55 /2/1970 61
ID=333333333 RACE=Asian ETHNICITY=Non Hispanic or Latino
Gender=Male Date=. _ERROR_=1 _N_=2
Kurt_Bremser
Super User

Add a delimiter to the INFILE statement, and the proper informat:

data BH;
infile
  'C:\desktop\NewDemo\apeal2.csv'
  dlm=','
  dsd
  firstobs=2
  truncover
;
length ID 8 RACE $32 ETHNICITY $40 Gender $20 date 4;
input ID RACE ETHNICITY Gender Date :mmddyy10.;
format Date mmddyy10.;
run;
Yughaber
Quartz | Level 8
Thank you so much!! This worked 🙂 I was pounding my head for so long. I've been following your replies in numerous posts and there is a lot to learn from you.
Shmuel
Garnet | Level 18

You did not assigned informat for the input date.

 

Please post:

  • a sample of your input CSV file - at least 3 lines.
  • please post the full log.
  • Use the '<>' menu option and copy/paste the sample lines as the log into the open window.

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
  • 5 replies
  • 2565 views
  • 1 like
  • 3 in conversation