<?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: Read a bunch of files in input in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981017#M43600</link>
    <description>&lt;P&gt;This SAS Note shows how to do that:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/techsup/notes/v8/24/707.html" target="_self"&gt;https:/https://support.sas.com/techsup/notes/v8/24/707.html/support.sas.com/techsup/notes/v8/24/707.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Dec 2025 12:52:23 GMT</pubDate>
    <dc:creator>Kathryn_SAS</dc:creator>
    <dc:date>2025-12-18T12:52:23Z</dc:date>
    <item>
      <title>Read a bunch of files in input</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981003#M43597</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have a number of .csv files (50) in the same folder.&lt;/P&gt;
&lt;P&gt;Each file is named: PRJ__20221201_13227_MF&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;PRJ__20221201_13227_TR&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;PRJ__20221201_13227_RECOV&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PRG__&lt;/P&gt;
&lt;P&gt;20221201_&lt;/P&gt;
&lt;P&gt;13227_&amp;nbsp;&lt;/P&gt;
&lt;P&gt;are present and the same in all file names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to read all the files in input without doing "proc import" for all files every time?&lt;/P&gt;
&lt;P&gt;It is preferable that the read files be named with the suffix, e.g., MF, TR, RECOV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 10:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981003#M43597</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-12-18T10:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Read a bunch of files in input</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981015#M43598</link>
      <description>&lt;P&gt;The best way is to create based on the name of the file a SAS Data Step that will segregate each file type to a specific table and afterwards in each file you will perform a loop that will eventually read each file and append to the target destination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example would be something like the below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* example of how you should segregate the file based on type*/


data files;
	length filename $50 path $100;
	infile datalines dlm="|";
	input filename $ path $;
datalines;
PRJ__20221201_13227_MF|C:\Users\Prophet\Files\
PRJ__20221201_13227_TR|C:\Users\Prophet\Files\
PRJ__20221201_13227_RECOV|C:\Users\Prophet\Files\
;
run;


data mf tr recov;
	set files;
	if find(filename, "_MF")&amp;gt;0 then output mf;
	else if find(filename, "_TR")&amp;gt;0 then output tr;
	else if find(filename, "_RECOV")&amp;gt;0 then output recov;
run;

%macro read_mf;

	data mf;
		set mf;
		id = _N_;
	run;
	proc sql noprint;
		select max(id) as :max_id from mf;
	quit;

	%do i = 1 %to &amp;amp;max_id;
		/*for each file in the location*/
		proc sql noprint;
			select catx('\',path, filename) into :file where id = &amp;amp;i;
		quit;

		/*read the contents of the csv via proc import or datastep */


		/*append the result in a target table */


	%end;
		

	
%mend;

%macro read_tr;
	/*same for the other files*/
%mend;


%macro read_recov;
	/*same for recov*/
%mend;


/*macro invocation*/

%read_mf;
%read_recov;
%read_tr;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should however, include the path for the file that you are trying to read and store in a sas dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 12:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981015#M43598</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2025-12-18T12:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read a bunch of files in input</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981016#M43599</link>
      <description>&lt;P&gt;Searching the forums is always a good place to start. This has been discussed many times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one such discussion:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/td-p/863674" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-read-multiple-CSV-files-using-SAS/td-p/863674&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 13:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981016#M43599</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-12-18T13:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read a bunch of files in input</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981017#M43600</link>
      <description>&lt;P&gt;This SAS Note shows how to do that:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/techsup/notes/v8/24/707.html" target="_self"&gt;https:/https://support.sas.com/techsup/notes/v8/24/707.html/support.sas.com/techsup/notes/v8/24/707.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 12:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981017#M43600</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-12-18T12:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Read a bunch of files in input</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981019#M43601</link>
      <description>&lt;P&gt;Do all of the files use the same structure?&amp;nbsp; That is they have the same variables in the same order?&lt;/P&gt;
&lt;P&gt;If so then yes you can read multiple files as if they were one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you can use a wild card in the INFILE statement.&amp;nbsp; You can use the FILENAME= option to get the current file's name so you can skip the header records.&amp;nbsp; Plus if you need to pull out the suffix on the filename as a variable you can do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example if each file has 4 variables, two of which are character strings and one is a date and the last is a plain old number then the code might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length filename $256 suffix $8 ;
  infile 'PRJ__20221201_13227_*.csv' dsd truncover filename=filename;
  input @;
  if filename ne lag(filename) then delete;
  suffix=scan(filename,-2,'._');
  length c1 $10 d1 8 c2 $3 n1 8;
  format d1 yymmdd10.;
  informat d1 mmddyy.;
  input c1--n1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 16:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981019#M43601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-18T16:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Read a bunch of files in input</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981077#M43602</link>
      <description>&lt;P&gt;If these files have the same data constructure, that would be easy by FILEVAR= option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data path;
input path $80.;
cards;
c:\temp\a\PRJ__20221201_13227_MF.txt
c:\temp\a\PRJ__20221201_13228_MF.txt
;

data MF;
set path;
length from_file file $ 80;
infile dummy filevar=path end=last filename=file truncover;
from_file=file;
do until(last);
 input a $ b $ c $;
 output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't like to type file name by hand, try this one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
data path;
input path $80.;
cards;
c:\temp\a\PRJ__20221201_13227_MF.txt
c:\temp\a\PRJ__20221201_13228_MF.txt
;
*/

%let path= c:\temp\a ;
data path;
length path $ 200;
rc=filename('x',"&amp;amp;path.");
did=dopen('x');
do i=1 to dnum(did);
 file=dread(did,i);
 if prxmatch('/.+MF\.txt$/i',strip(file)) then do;
  path=catx('\',"&amp;amp;path.",file);
  output;
 end;
end;
keep path;
run;


data MF;
set path;
length from_file file $ 200;
infile dummy filevar=path end=last filename=file truncover;
from_file=file;
do until(last);
 input a $ b $ c $;
 output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Dec 2025 08:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Read-a-bunch-of-files-in-input/m-p/981077#M43602</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-12-19T08:28:24Z</dc:date>
    </item>
  </channel>
</rss>

