1
votes

I need to use the INFILE statement to read a file called np_traffic.csv, name the table traffic2, and only import a column called ReportingDate as a character.

Current Code is giving me the error

"The data set WORK.TRAFFIC2 may be incomplete. When this step was stopped there were 0 observations and 1 variables."

enter image description here

DATA traffic2;
INFILE “E:/Documents/Week 2/np_traffic.csv”
dsd firstobs=2;
INPUT ReportingDate $;
RUN;
2
Looks like you have smart quotes. Use single quotes. May also need \ instead of /.data _null_
You posted a picture of a spreadsheet, but your program is trying to read a text file. Which type of file do you actually have? Look at the file with a text editor instead of with a spreadsheet program.Tom
You cannot read a file in this manner. You need to read all columns, I suspect, but only ReportingDate as a date or drop the other fields after. If you're uncertain of the code, first run PROC IMPORT, check the log and adapt yours as needed.Reeza
Update the question, paste in some of the lines from the actual csv file, copied from viewing the data file in Notepad.Richard

2 Answers

1
votes

Let's assume that you really have a delimited text file, which is what a CSV file is, instead of the spreadsheet you pictured in the photograph in your post. To read the 6th field in a line you need to first read the first 5 fields. That does not mean you need use the values read from those fields.

data traffic2;
  infile “E:/Documents/Week 2/np_traffic.csv”
    dsd firstobs=2
  ;
  length dummy $1 ReportingDate $12;
  input 5*dummy ReportingDate ;
  drop dummy;
run;
0
votes

I would suggest to try it this way:

data traffic2;
 drop a b c d e g;
 infile 'E:\Documents\Week 2\np_traffic.csv' dsd dlm='<Insert your delimiter>' firstobs=2;
 input a b c d e f g;
run;

https://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&docsetVersion=9.4&locale=en