DATA Step, Macro, Functions and more

Reading multiple CSVs with EOV

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Reading multiple CSVs with EOV

Hi all,

 

I am trying to read in multiple csvs with headers on the first line using wildcards in the infile command. I heard that to skip the first line in the files one could use EOV however I didn't get a chance to figure out how it works.

 

If i just say the piece of code below, I still get the headers imported.

infile '\\*_20160831*.csv' dlm=';' lrecl=10000 dsd missover eov=eov firstobs=2;

if eov then input;

input 
   column_1
;

If I however use the piece of code below it works.

infile '\\*_20160831*.csv' dlm=';' lrecl=10000 dsd missover eov=eov firstobs=2;

input @;
if eov then input;

input column_1;

What does this input @; command do? I could not find any documentation on it ...

 

Thank you.


Accepted Solutions
Solution
‎09-03-2016 01:19 AM
Super User
Super User
Posts: 6,495

Re: Reading multiple CSVs with EOV

[ Edited ]

Trailing @ means that you are not done reading this line yet. SAS keeps the line current and it is available for another INPUT statement on the same iteration of the data step.

 

Here is a simple example that uses that to read in multiple observations from one line.

data mydata;
   input id $ @;
   do year=2010 to 2015 ;
      input cost @;
      output;
   end;
cards;
Milk 1 2 3 4 5 6 
Beer 2 3 4 5 6 7
;

The reason that you need it is because the EOV flag is not set until SAS sees that you are opening another data file and it does not know this until you try to read from it.  So you need the INPUT statement to set the EOV flag, but you don't want to try to read hte column headers into your variables.  So you read the line, but do not try to read any variable values by using the bare INPUT statement with only the trailing @ pointer control command.

View solution in original post


All Replies
Solution
‎09-03-2016 01:19 AM
Super User
Super User
Posts: 6,495

Re: Reading multiple CSVs with EOV

[ Edited ]

Trailing @ means that you are not done reading this line yet. SAS keeps the line current and it is available for another INPUT statement on the same iteration of the data step.

 

Here is a simple example that uses that to read in multiple observations from one line.

data mydata;
   input id $ @;
   do year=2010 to 2015 ;
      input cost @;
      output;
   end;
cards;
Milk 1 2 3 4 5 6 
Beer 2 3 4 5 6 7
;

The reason that you need it is because the EOV flag is not set until SAS sees that you are opening another data file and it does not know this until you try to read from it.  So you need the INPUT statement to set the EOV flag, but you don't want to try to read hte column headers into your variables.  So you read the line, but do not try to read any variable values by using the bare INPUT statement with only the trailing @ pointer control command.

Contributor
Posts: 24

Re: Reading multiple CSVs with EOV

Thank you very much for the excellent detailed explanation Smiley Happy
☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 367 views
  • 0 likes
  • 2 in conversation