<?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: Reading multiple csv files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369231#M88125</link>
    <description>&lt;P&gt;Try the call execute like below this is an untested code. The want dataset will have the date value in new variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do i = 1 to 250;
new=intnx('day',input('20160104',yymmdd8.),i-1);
output;
end;
format new yymmddn8.;
run;

data _null_;
set want;
call execute("data want;
Infile 'C:\Temp\abc"||new||".csv' DLM = ','
Lrecl = 32000 DSD Truncover firstobs = 1;
Informat fname $60. ticker $5. ;
Input
fname ticker VarA VarB VarC VarD VarE VarF /*These are not the names of the actual Variables but just examples */;
run;

Data Want;
set want;
String = scan ( fname , -1 , , 'a' ); 

Date = input (string , yymmdd8.);
format date mmddyy10.;
run;

data want (keep = date ticker VarA VarB VarC); set want;
run;

data want"||new||" ; set want;
format VarM 12. ;
VarM = (VarB+VarC)/200;
run;");

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Jun 2017 17:22:48 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2017-06-21T17:22:48Z</dc:date>
    <item>
      <title>Reading multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369212#M88115</link>
      <description>&lt;P&gt;I have about 250 csv files. &amp;nbsp;They are named abc20160104 abc20160105 abc20160106 and so forth&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for each individual file I have written the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;Infile 'C:\Temp\abc20160104.csv' DLM = ','&lt;BR /&gt;Lrecl = 32000 DSD Truncover firstobs = 1;&lt;BR /&gt;Informat fname $60. ticker $5. ;&lt;BR /&gt;Input&lt;BR /&gt;fname ticker VarA VarB VarC VarD VarE VarF /*These are not the names of the actual Variables but just examples */;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Data Want;&lt;BR /&gt;set want;&lt;BR /&gt;String = scan ( fname , -1 , , 'a' );&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date = input (string , yymmdd8.);&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want (keep = date ticker VarA VarB VarC); set want;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want ; set want;&lt;/P&gt;&lt;P&gt;format VarM 12. ;&lt;/P&gt;&lt;P&gt;VarM = (VarB+VarC)/200;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;/* And so on -- there are a few more lines */&lt;/P&gt;&lt;P&gt;After the code for each individual file I want the output to be saved as 20160104 &amp;nbsp;20160105 or the file name which was read in;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Thanx in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Randy&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 16:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369212#M88115</guid>
      <dc:creator>RandyStan</dc:creator>
      <dc:date>2017-06-21T16:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369229#M88123</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133090"&gt;@RandyStan&lt;/a&gt;&amp;nbsp;So what's your question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can make some assumptions and these would be my answers:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n0ctmldxf23ixtn1kqsoh5bsgmg8.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 17:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369229#M88123</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-21T17:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reading multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369231#M88125</link>
      <description>&lt;P&gt;Try the call execute like below this is an untested code. The want dataset will have the date value in new variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do i = 1 to 250;
new=intnx('day',input('20160104',yymmdd8.),i-1);
output;
end;
format new yymmddn8.;
run;

data _null_;
set want;
call execute("data want;
Infile 'C:\Temp\abc"||new||".csv' DLM = ','
Lrecl = 32000 DSD Truncover firstobs = 1;
Informat fname $60. ticker $5. ;
Input
fname ticker VarA VarB VarC VarD VarE VarF /*These are not the names of the actual Variables but just examples */;
run;

Data Want;
set want;
String = scan ( fname , -1 , , 'a' ); 

Date = input (string , yymmdd8.);
format date mmddyy10.;
run;

data want (keep = date ticker VarA VarB VarC); set want;
run;

data want"||new||" ; set want;
format VarM 12. ;
VarM = (VarB+VarC)/200;
run;");

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2017 17:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369231#M88125</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-06-21T17:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369233#M88126</link>
      <description>&lt;P&gt;What is the question?&lt;/P&gt;
&lt;P&gt;Also you seem to keep using multiple data steps to perform things that can be done in a single step. &amp;nbsp;Is there a reason for that? &amp;nbsp;Did you leave out other lines of code that would make it impossible to combine those steps?&lt;/P&gt;
&lt;P&gt;Can you just read them all into the same dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'C:\Temp\abc*.csv' DSD DLM = ',' lrecl = 32000 truncover;
  input @;
  if upcase(_infile_) =: 'FNAME,' then input;
  length fname $60 ticker $5 ;
  input fname ticker VarA VarB VarC VarD VarE VarF
 /*These are not the names of the actual Variables but just examples */
  ;
  length string $60 ;
  string = scan ( fname , -1 , , 'a' ); 
  drop string ;
  date = input (string , yymmdd8.);
  format date mmddyy10.;
  VarM = (VarB+VarC)/200;
  format VarM 12. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2017 17:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369233#M88126</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-21T17:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Reading multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369236#M88127</link>
      <description>&lt;P&gt;Few notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) All your steps can be done in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
       Infile 'C:\Temp\abc20160104.csv' DLM = ','
               Lrecl = 32000 DSD Truncover firstobs = 1;
      Informat fname $60. ticker $5. ;
      Input  fname ticker VarA VarB VarC VarD VarE VarF ;

      String = scan ( fname , -1 , , 'a' ); 
      Date = input (string , yymmdd8.);
      VarM = (VarB+VarC)/200;
      format date mmddyy10.  VarM 12.;
      keep date ticker VarA VarB VarC;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In order to have datasets named as desired and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;assuming all csv files are of same format, i.e. same order of variables and same length,&lt;/P&gt;
&lt;P&gt;you can convert the code into macro, supplying the date part of the file name as argument,&lt;/P&gt;
&lt;P&gt;then run the macro - either a row per name or within a loop creating dates from first to last dates given,&lt;/P&gt;
&lt;P&gt;something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro single(datex);  /* datex given as yyyymmdd format */
    data f&amp;amp;datex;
       Infile "C:\Temp\abc&amp;amp;datex..csv' DLM = ','
               Lrecl = 32000 DSD Truncover firstobs = 1;
      Informat fname $60. ticker $5. ;
      Input  fname ticker VarA VarB VarC VarD VarE VarF ;

      String = scan ( fname , -1 , , 'a' ); 
      Date = input (string , yymmdd8.);
      VarM = (VarB+VarC)/200;
      format date mmddyy10.  VarM 12.;
      keep date ticker VarA VarB VarC;
   run;
%mend single;

%let fromdate = 20160101;  /* adapt period dates */
%let uptodate = 20161201;
data _null_;
     fromdate = input("&amp;amp;fromdate",yymmddn8.);
     updodate = input("&amp;amp;uptodate",yymmddn8.);

    do i=fromdate to uptodate;
         datex = put(i, yymmdd8.);
         line = '%single(' || datex|| ');'
         call execute(line);
    end;
run;
         &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I haven't checked it, so maybe you'll need &amp;nbsp;recombine the line= and call execute statements;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 17:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-multiple-csv-files/m-p/369236#M88127</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-21T17:36:16Z</dc:date>
    </item>
  </channel>
</rss>

