<?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 Import a list of files by looping over dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664808#M198671</link>
    <description>&lt;P&gt;I have a folder of CSV files named based on daily dates, such as "data_20150101". I am trying to import them and append to one single dataset. My current code is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import(start, end);
	%let start = %sysfunc(inputn(&amp;amp;start, anydtdte9.));
	%let end = %sysfunc(inputn(&amp;amp;end, anydtdte9.));
	%let dif = %sysfunc(intck('day', &amp;amp;start, &amp;amp;end));
    	%do i = 0 %to &amp;amp;dif;
			%let date = %sysfunc(intnx('day', &amp;amp;start, &amp;amp;i, 'e'), yymmddn8.);
				data data_new;
					infile "&amp;amp;in_path\data_&amp;amp;date..csv" delimiter = ',' dsd missover lrecl = 32767 firstobs = 2; 
					informat 
					var1 $10.
					var2 10.;
					input var1 var2;
				run;
				proc append base = want data = data_new; run;
		%end;
%mend;

%import(20150101, 20151231);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run the code, nothing happens. I got a message:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;WARNING: The quoted string currently being processed has become more than 262 bytes long. You&lt;BR /&gt;might have unbalanced quotation marks.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Thu, 25 Jun 2020 00:49:57 GMT</pubDate>
    <dc:creator>xyxu</dc:creator>
    <dc:date>2020-06-25T00:49:57Z</dc:date>
    <item>
      <title>Import a list of files by looping over dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664808#M198671</link>
      <description>&lt;P&gt;I have a folder of CSV files named based on daily dates, such as "data_20150101". I am trying to import them and append to one single dataset. My current code is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import(start, end);
	%let start = %sysfunc(inputn(&amp;amp;start, anydtdte9.));
	%let end = %sysfunc(inputn(&amp;amp;end, anydtdte9.));
	%let dif = %sysfunc(intck('day', &amp;amp;start, &amp;amp;end));
    	%do i = 0 %to &amp;amp;dif;
			%let date = %sysfunc(intnx('day', &amp;amp;start, &amp;amp;i, 'e'), yymmddn8.);
				data data_new;
					infile "&amp;amp;in_path\data_&amp;amp;date..csv" delimiter = ',' dsd missover lrecl = 32767 firstobs = 2; 
					informat 
					var1 $10.
					var2 10.;
					input var1 var2;
				run;
				proc append base = want data = data_new; run;
		%end;
%mend;

%import(20150101, 20151231);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run the code, nothing happens. I got a message:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;WARNING: The quoted string currently being processed has become more than 262 bytes long. You&lt;BR /&gt;might have unbalanced quotation marks.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 00:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664808#M198671</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2020-06-25T00:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Import a list of files by looping over dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664809#M198672</link>
      <description>&lt;P&gt;Are you missing a semicolon after your informat statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_new;
	infile "/sasnas/ovations/fic/phi2/mmr/prod/PRS_CGD_Driver_file.xlsx" delimiter = ',' dsd missover lrecl = 32767 firstobs = 2; 
	informat 
	var1 $10.
	var2 10.;
	input var1 var2;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 23:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664809#M198672</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-06-24T23:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Import a list of files by looping over dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664818#M198675</link>
      <description>&lt;P&gt;If you want to read all of the files whose names start with data_ in that folder then NO explicit loop is needed;&lt;/P&gt;
&lt;P&gt;You might try this code to see what happens:&lt;/P&gt;
&lt;PRE&gt;data data_new;
	infile "&amp;amp;in_path\data_*.csv" delimiter = ',' 
          dsd missover lrecl = 32767 firstobs = 2; 
	informat 
	var1 $10.
	var2 10.
   ;
	input var1 var2;
run;&lt;/PRE&gt;
&lt;P&gt;The * wildcard in the file name will attempt to read every file in the folder that starts with data_&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;If you run that you will get an "invalid data for var2" for each file when the header row is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That header row problem can be addressed with some additional options and conditional statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously untested because I don't have your folders or data sets:&lt;/P&gt;
&lt;PRE&gt;data data_new;
	infile "&amp;amp;in_path\data_*.csv" delimiter = ',' 
          dsd missover lrecl = 32767 firstobs = 2
          eov=skip; 
	informat 
	var1 $10.
	var2 10.
   ;
   input @;
   if skip then skip=0;
   else do;
      input var1 var2;&lt;BR /&gt;      output;
   end;

run;&lt;/PRE&gt;
&lt;P&gt;The option EOV sets a variable, skip in this case to the value of 1 when the first first line of a new file is read. The Input @; starts to read the line of data but the @ holds the pointer on that line. Then we test the Skip variable. If the value is 1 then 'if skip' is true and we just reset the value otherwise we know we are not on a header row and the input reads the data line. The explicit output is to only output data when not on a header row.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 00:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664818#M198675</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-25T00:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Import a list of files by looping over dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664819#M198676</link>
      <description>Oh sorry about that. It was missed when I was simplifying that part. Added back.</description>
      <pubDate>Thu, 25 Jun 2020 00:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664819#M198676</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2020-06-25T00:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Import a list of files by looping over dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664821#M198679</link>
      <description>This approach works amazingly well. For the header issue, I can easily delete observations that are written from headers. Thank you!</description>
      <pubDate>Thu, 25 Jun 2020 01:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-a-list-of-files-by-looping-over-dates/m-p/664821#M198679</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2020-06-25T01:18:28Z</dc:date>
    </item>
  </channel>
</rss>

