<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to read multiple CSV files using SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863677#M341146</link>
    <description>&lt;P&gt;Since a file reference can also be used for output, wildcards don't make sense there.&lt;/P&gt;
&lt;P&gt;Do everything in the INFILE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  infile  "/path/to/folder/*.csv" dlm=',' firstobs=2;
  input var1 var2 var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to add code to skip the header line in every new file.&lt;/P&gt;</description>
    <pubDate>Sun, 12 Mar 2023 16:43:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-03-12T16:43:51Z</dc:date>
    <item>
      <title>How to read multiple CSV files using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863674#M341144</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am new to SAS programming and I am trying to read multiple CSV files into SAS. I have tried using the infile statement with a wildcard to read all the files in a folder, but it doesn't seem to be working. Can someone please guide me on how to read multiple CSV files in SAS?&lt;/P&gt;&lt;P&gt;Here's the code I am using:&lt;/P&gt;&lt;PRE&gt;filename files "/path/to/folder/*.csv";

data mydata;
  infile files dlm=',' firstobs=2;
  input var1 var2 var3;
run;&lt;/PRE&gt;&lt;P&gt;I am not getting any errors, but it seems like only the first file is being read. I have searched online for a solution but haven't been able to find one that works for me. Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 12 Mar 2023 15:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863674#M341144</guid>
      <dc:creator>Yoshihisa-Yokoi</dc:creator>
      <dc:date>2023-03-12T15:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to read multiple CSV files using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863676#M341145</link>
      <description>&lt;P&gt;Your code will only skip the header line on the FIRST file it finds.&lt;/P&gt;
&lt;P&gt;To skip all of the headers use the FILENAME= option of the INFILE statement to create a variable to contain the name of the current file so you can skip the header line of each file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  length filen $256;
  infile "/path/to/folder/*.csv" dsd truncover filename=filen;
  input @@;
  if filen ne lag(filen) then delete;
  input var1 var2 var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The variable created by the FILENAME= option is not output. So if you want to keep the name of the file that contributed the current observation then add another variable.&amp;nbsp; This code will also add a simple numeric variable to count how many files have been read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  length filen $256;
  infile "/path/to/folder/*.csv" dsd truncover filename=filen;
  input @@;
  if filen ne lag(filen) then do;
     fileno+1;
     delete;
  end;
  input var1 var2 var3;
  filename=filen;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Mar 2023 16:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863676#M341145</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-12T16:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to read multiple CSV files using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863677#M341146</link>
      <description>&lt;P&gt;Since a file reference can also be used for output, wildcards don't make sense there.&lt;/P&gt;
&lt;P&gt;Do everything in the INFILE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  infile  "/path/to/folder/*.csv" dlm=',' firstobs=2;
  input var1 var2 var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to add code to skip the header line in every new file.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Mar 2023 16:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/m-p/863677#M341146</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-12T16:43:51Z</dc:date>
    </item>
  </channel>
</rss>

