<?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 Read all csv files (without specifying the filenames) from a unix folder and create a joined dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719047#M222573</link>
    <description>&lt;P&gt;Hi, I have to read a folder in unix containg multiple csv files with the same structure and create a dataset with all the variables in these files. Since the file names change, I can't use these finlenames in&amp;nbsp;infile statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to use any macro to perform this task?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 12 Feb 2021 23:05:36 GMT</pubDate>
    <dc:creator>DritanB</dc:creator>
    <dc:date>2021-02-12T23:05:36Z</dc:date>
    <item>
      <title>Read all csv files (without specifying the filenames) from a unix folder and create a joined dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719047#M222573</link>
      <description>&lt;P&gt;Hi, I have to read a folder in unix containg multiple csv files with the same structure and create a dataset with all the variables in these files. Since the file names change, I can't use these finlenames in&amp;nbsp;infile statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to use any macro to perform this task?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 23:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719047#M222573</guid>
      <dc:creator>DritanB</dc:creator>
      <dc:date>2021-02-12T23:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read all csv files (without specifying the filenames) from a unix folder and create a joined dat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719049#M222575</link>
      <description>You don't need a macro (you can but it's more work) you can use wildcards. &lt;BR /&gt;Assuming all the files are the same you can easily read all in a single data step by wildcarding the folder.&lt;BR /&gt;&lt;BR /&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;</description>
      <pubDate>Fri, 12 Feb 2021 23:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719049#M222575</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-12T23:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Read all csv files (without specifying the filenames) from a unix folder and create a joined dat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719059#M222583</link>
      <description>Thank you. I forgot to mention in my initial post that in the dataset that I have to create from all these csv files, I will also have to include a new variable containing the name of the csv file for each observation. Will I be able to do that by modyfying the solution you provided?</description>
      <pubDate>Sat, 13 Feb 2021 00:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719059#M222583</guid>
      <dc:creator>DritanB</dc:creator>
      <dc:date>2021-02-13T00:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Read all csv files (without specifying the filenames) from a unix folder and create a joined dat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719078#M222596</link>
      <description>&lt;P&gt;Next code is designed to generate a temporary program to do what you want.&lt;/P&gt;
&lt;P&gt;It contains few steps:&lt;/P&gt;
&lt;P&gt;1) create a list of files to read into a sas dataset.&lt;/P&gt;
&lt;P&gt;2) a simple macro to read one file and create a TEMP data set.&lt;/P&gt;
&lt;P&gt;3) a dad step to generate the required code as temporary program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; it is recommended to put it to log first for checking and debug.&lt;/P&gt;
&lt;P&gt;4) %include the temporary program to execute it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dirlist(path,suffix);
	data dirlist(keep=path fname);
	    retain path "&amp;amp;path";
		rc=filename ("fdir","&amp;amp;path");  
		did=dopen("fdir");   
		if did&amp;gt;0 then do;    
		   num=dnum(did); 
           /* call symput('n_files',put(num,3.)); &amp;lt;&amp;lt;&amp;lt; not used */		   
		   do i = 1 to num;
			  fname=dread(did,i);  
			  if lowcase(scan(fname,-1,'.')) = lowcase("&amp;amp;suffix") 
			  then output;
		   end;
		end;
	 run;   
%mend;
%dirlist(&amp;lt;path&amp;gt;,csv);

%macro code;
   data temp;
    ... enter here your INPUT satement code to read a record ...
   run;
%mend;

%let want = &amp;lt;output dataset name &amp;gt;;
filename prog "&amp;lt;path&amp;gt;/temp_prog.sas";   
data _null_;
 set dirlist;
	 file prog;  /* for easy debug replace with put log */
     if _n_ =1 then do;
	    cmd = "proc delete data=&amp;amp;want; run;"; 
		put cmd;
	 end;
	 
	 cmd = "filename finp '" ||strip(path)||'/'||strip(fname)||".csv)';";
	 put cmd;
     cmd = "%code;";
	 put cmd;
	 cmd = "proc append base=&amp;amp;want data=temp; run;";
	 put cmd;
	 cmd = 'filename finp clear;';
	 put cmd;
run;
/** if seems ok then run next line **/
%include prog;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;code was not tested. if any issue please post the log using FILE LOG instead FILE PROG.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Feb 2021 09:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719078#M222596</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-13T09:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Read all csv files (without specifying the filenames) from a unix folder and create a joined dat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719085#M222602</link>
      <description>&lt;P&gt;Use the FILENAME= option of the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;INFILE&lt;/A&gt;&amp;nbsp;statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length fname filename $200;
infile "/path/*.csv" filename=fname /* other options */;
input
  .....
;
filename = fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The two variables are necessary because the one used in the option will automatically be excluded from any output dataset.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Feb 2021 08:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719085#M222602</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-13T08:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Read all csv files (without specifying the filenames) from a unix folder and create a joined dat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719225#M222673</link>
      <description>The solution in the link actually does that already.</description>
      <pubDate>Sun, 14 Feb 2021 16:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-all-csv-files-without-specifying-the-filenames-from-a-unix/m-p/719225#M222673</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-14T16:36:02Z</dc:date>
    </item>
  </channel>
</rss>

