<?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: Multiple days CSV file import to SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327316#M73006</link>
    <description>&lt;P&gt;The codes help and I have added the proc import codes.&amp;nbsp; When I run the proc import codes and use the file_name, I can only import the last day of the data instead of all 31 (days) files.&amp;nbsp; Any comments? Thanks.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%let month=1;&lt;BR /&gt;%let year=2017;&lt;BR /&gt;%let file_prefix=MB0101D;&lt;BR /&gt;%let file_suffix=txt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;start = mdy(&amp;amp;month,2,&amp;amp;year);&lt;BR /&gt;end = intnx('month',start,1,'begin');&lt;BR /&gt;length file_name $30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do date = start to end;&lt;BR /&gt;file_name = "&amp;amp;file_prefix" !! put(date,ddmmyyn8.) !! ".&amp;amp;file_suffix";&lt;BR /&gt;call symput('file_name',trim(file_name));&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;proc import datafile="D:\&amp;amp;file_name" out=test dbms=TAB replace;&lt;BR /&gt;getnames=no;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2017 10:18:43 GMT</pubDate>
    <dc:creator>scb</dc:creator>
    <dc:date>2017-01-25T10:18:43Z</dc:date>
    <item>
      <title>Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327270#M72994</link>
      <description>&lt;P&gt;Every month I have daily CSV files (from 2nd day of the month to 1st day of next month, e.g. 2 Oct to 1 Nov).&amp;nbsp; I have no problem in importing the CSV file individually into SAS.&amp;nbsp; May I know how to import all 31 days CSV in one csv import statement by controlling the date?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is 2 CSV files, the last 6 digit is the date of the file in format ddmmyyyy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea? Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 07:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327270#M72994</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2017-01-25T07:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327284#M72995</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That may depend on how you are importing those files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please&amp;nbsp;share the code that you are using for importing one file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 08:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327284#M72995</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-25T08:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327286#M72996</link>
      <description>&lt;P&gt;You can concatenate filenames in a filename statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in ('file1.dat','file2.dat','file3.dat');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Those files will be read sequentially when used as infile in a data step.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 08:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327286#M72996</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-25T08:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327288#M72998</link>
      <description>&lt;P&gt;To expand on my first answer, see this example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=1;
%let year=2017;
%let file_prefix=datafile_;
%let file_suffix=dat;

data _null_;
start = mdy(&amp;amp;month,2,&amp;amp;year);
end = intnx('month',start,1,'begin');
length filestring $1000 file_name $30;
do date = start to end;
  file_name = "'&amp;amp;file_prefix" !! put(date,ddmmyyn8.) !! ".&amp;amp;file_suffix'";
  filestring = catx(',',filestring,file_name);
end;
call symput('filestring',trim(filestring));
run;

%put &amp;amp;filestring;

filename in (&amp;amp;filestring);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jan 2017 08:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327288#M72998</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-25T08:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327290#M73000</link>
      <description>&lt;P&gt;As you have a code to read individual CSV file , we don't need the files but only their names,&lt;/P&gt;
&lt;P&gt;that is: &amp;nbsp;from&lt;STRONG&gt;&amp;nbsp;MB0101D31102016.csv&amp;nbsp;&lt;/STRONG&gt;to&amp;nbsp;&lt;STRONG&gt;MB0101D01112016.csv;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then create a filename to include all those files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let start_date=31OCT2016;&lt;/P&gt;
&lt;P&gt;%let end_date = 01NOV2016;&lt;/P&gt;
&lt;P&gt;data _NULL_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; length fnames $1000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;st = input("&amp;amp;start_date", date9.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;nd = input("end_date",date9.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do i=st to nd by 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; datex = put(i,ddmmyyn8.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fname = 'MB0101D'||datex||'.csv';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fnames = catx('" "', fnames,fanme);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; fnames = '"'||fnames||'"';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; rc = filename csv_all (fnames);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;infile csv_all truncover;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ... your code to read variables ...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 08:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327290#M73000</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-25T08:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327291#M73001</link>
      <description>&lt;P&gt;You should create a macro %import_file() &amp;nbsp;what will import csv file and this macro would need date parameter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_file(date_val);&lt;BR /&gt;&lt;BR /&gt;proc import data='MB101&amp;amp;date_val'&lt;BR /&gt;   out = temp_F&lt;BR /&gt;  replace;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _null_;
t =today();
first_day=intnx('month',today(),0,'b');
last_day=intnx('month',today(),0,'e');
format t first_day  last_day counter ddmmyyn8. ;
counter=first_day;
do while (counter &amp;lt;=last_day);
counter+1;
put '%import_file(' counter ');';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 09:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327291#M73001</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2017-01-25T09:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327296#M73002</link>
      <description>&lt;P&gt;I got this error message, is it due to the SAS version, mine is SAS 9.2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rc = filename csv_all (fnames);&lt;BR /&gt;-------&lt;BR /&gt;22&lt;BR /&gt;68&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, ;, &amp;lt;,&lt;BR /&gt;&amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=,&lt;BR /&gt;{, |, ||, ~=.&lt;/P&gt;&lt;P&gt;ERROR 68-185: The function CSV_ALL is unknown, or cannot be accessed.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 09:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327296#M73002</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2017-01-25T09:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327298#M73003</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80526"&gt;@scb&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I got this error message, is it due to the SAS version, mine is SAS 9.2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rc = filename csv_all (fnames);&lt;BR /&gt;-------&lt;BR /&gt;22&lt;BR /&gt;68&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, ;, &amp;lt;,&lt;BR /&gt;&amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=,&lt;BR /&gt;{, |, ||, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 68-185: The function CSV_ALL is unknown, or cannot be accessed.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I guess that should have been&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc = filename ('csv_all',fnames);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jan 2017 09:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327298#M73003</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-25T09:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327300#M73004</link>
      <description>&lt;P&gt;Sorry, I had few mis types. Here is a tested code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date=31OCT2016;
%let end_date = 01NOV2016;
data _NULL_;
        length fnames $1000;
       st = input("&amp;amp;start_date", date9.);
       nd = input("&amp;amp;end_date",date9.);
       do i=st to nd by 1;
            datex = put(i,ddmmyyn8.);
            fname = 'MB0101D'||datex||'.csv';
            fnames = catx('" "', fnames,fname);
      end;
      fnames = '"'||fnames||'"';
      rc = filename('csv_all',fnames);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jan 2017 09:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327300#M73004</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-25T09:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327316#M73006</link>
      <description>&lt;P&gt;The codes help and I have added the proc import codes.&amp;nbsp; When I run the proc import codes and use the file_name, I can only import the last day of the data instead of all 31 (days) files.&amp;nbsp; Any comments? Thanks.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%let month=1;&lt;BR /&gt;%let year=2017;&lt;BR /&gt;%let file_prefix=MB0101D;&lt;BR /&gt;%let file_suffix=txt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;start = mdy(&amp;amp;month,2,&amp;amp;year);&lt;BR /&gt;end = intnx('month',start,1,'begin');&lt;BR /&gt;length file_name $30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do date = start to end;&lt;BR /&gt;file_name = "&amp;amp;file_prefix" !! put(date,ddmmyyn8.) !! ".&amp;amp;file_suffix";&lt;BR /&gt;call symput('file_name',trim(file_name));&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;proc import datafile="D:\&amp;amp;file_name" out=test dbms=TAB replace;&lt;BR /&gt;getnames=no;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 10:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327316#M73006</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2017-01-25T10:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple days CSV file import to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327345#M73010</link>
      <description>&lt;P&gt;Compare my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
start = mdy(&amp;amp;month,2,&amp;amp;year);
end = intnx('month',start,1,'begin');
length filestring $1000 file_name $30;
do date = start to end;
  file_name = "'&amp;amp;file_prefix" !! put(date,ddmmyyn8.) !! ".&amp;amp;file_suffix'";
  filestring = catx(',',filestring,file_name);
end;
call symput('filestring',trim(filestring));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with yours:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
start = mdy(&amp;amp;month,2,&amp;amp;year);
end = intnx('month',start,1,'begin');
length file_name $30;
do date = start to end;
  file_name = "&amp;amp;file_prefix" !! put(date,ddmmyyn8.) !! ".&amp;amp;file_suffix";
  call symput('file_name',trim(file_name));
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and find the difference. You omitted the accumulation of filenames into a string, and moved the call symput into the do loop. Only the result of the last call symput will "survive", and that goes into the proc import. My code uses a fileref, which allows multiple filenames.&lt;/P&gt;
&lt;P&gt;I also recommend abandoning the guesssing procedure PROC IMPORT in favor of a data step written to file specifications.&lt;/P&gt;
&lt;P&gt;Within a data step, you can also take care of header lines that will appear everytime a new input file starts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 11:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-days-CSV-file-import-to-SAS/m-p/327345#M73010</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-25T11:39:37Z</dc:date>
    </item>
  </channel>
</rss>

