DATA Step, Macro, Functions and more

Import dirty csv data

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

Import dirty csv data

[ Edited ]

Hi, I'm trying to import the csv file that I downloaded from Bloomberg. I tried the method that I used before but it does not work properly (Error message in log). I attached the code and screenshot of csv file and SAS result here. Any suggestion for improving the code? Thanks a lot!

PROC IMPORT OUT= Bloomberg																/*Import three inventory data*/				
			DATAFILE= "E:\one_drive\OneDrive\Thesis\2017_Xusheng\Update1\1-Price\Data\Inventory\Bloomberg.csv"   
            DBMS=CSV REPLACE;				
     GETNAMES=YES;
     DATAROW=2; 
Run;

1522510123(1).pngCSV file1522510421(1).pngSAS Result 1522510637(1).pngLog error message


Accepted Solutions
Solution
‎04-02-2018 01:20 PM
Super User
Posts: 10,850

Re: Import dirty csv data

Try another option.

 

PROC IMPORT OUT= Bloomberg /*Import three inventory data*/
DATAFILE= "E:\one_drive\OneDrive\Thesis\2017_Xusheng\Update1\1-Price\Data\Inventory\Bloomberg.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;

guessingrows=32767;

DATAROW=2;
Run;

View solution in original post


All Replies
Super User
Super User
Posts: 8,279

Re: Import dirty csv data

The only errors your log are showing is when the DATE column contains '#VALUE1' instead of a date.

Sounds like you could just ignore the errors since they will only result in the DATE column having a missing value.

 

Otherwise write you own data step to read the CSV file.  You will then have complete control over how to handle those values.

 

PS  You posted a picture of a spreadsheet and labeled it a CSV file.  A CSV is a text file. Don't post pictures of text, just post the text. It is clearer, smaller and easier than posting photos. And if you do post a photo then post a photo of the actual object and not a version that has been transformed by being read into a program like Excel.

Contributor
Posts: 63

Re: Import dirty csv data

Thank you for replying, yes, I read the error message and did not
figure out how it affects my result. The date and event names are good but
the problem is with the numbers. Probably I will just create my own data
step.

I will keep in mind regarding the posting pictures.
Super User
Super User
Posts: 8,279

Re: Import dirty csv data

We cannot tell from the photos what issues you might have with the numbers. Post just a few rows of the actual data in the CSV file and of that data after PROC IMPORT read them (again as text and not photos) and explain it what way that are not correct.

Contributor
Posts: 63

Re: Import dirty csv data

Thank you, Tom. I've found the problem. It was inside my data. Invalid value in the date column ruins the rest of the data. Thank you.

Solution
‎04-02-2018 01:20 PM
Super User
Posts: 10,850

Re: Import dirty csv data

Try another option.

 

PROC IMPORT OUT= Bloomberg /*Import three inventory data*/
DATAFILE= "E:\one_drive\OneDrive\Thesis\2017_Xusheng\Update1\1-Price\Data\Inventory\Bloomberg.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;

guessingrows=32767;

DATAROW=2;
Run;

Contributor
Posts: 63

Re: Import dirty csv data

Thank you, Ksharp. I've found the problem and fixed that. 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 172 views
  • 1 like
  • 3 in conversation