<?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: Pulling files from an output folder without knowing the file names and merging them into a datas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575453#M162783</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139341"&gt;@kmardinian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not have that in my program yet, I was not sure how to call all the files without having to name them all individually.&lt;/P&gt;
&lt;P&gt;Is there a good way of doing that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had found this online:&lt;/P&gt;
&lt;PRE&gt;   %include "&amp;amp;dir\&amp;amp;name" /source2;&lt;/PRE&gt;
&lt;PRE&gt;   Filename filelist pipe "dir /b /s c:\temp\*.sas"; 
                                                                                   
   Data _null_;                                        
     Infile filelist truncover;
     Input filename $100.;
     Put filename=;
   Run; &lt;/PRE&gt;
&lt;P&gt;Would that work well for what I need to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then I can merge them without calling them separately as well?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would modify it to save it to a data set - check that it lists all the files you need and not the directories.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to filter it if you have other files in the same folder.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason I'm not suggesting wildcards, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; is, is because you have files in multiple folders and I don't think wildcards can handle that without multiple calls. And I'm assuming by 'merging' you mean append and add in the subject name as a field rather than merge to a wide data set because that doesn't makes sense to me. You can use his approach and repeat it several times or you can find all the file names and read them into a single data set in one step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The infile documentation has some examples but once you provide the code to read a single file we can help you convert it to the code you need to read all files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check that this gives you the file list with all the files you need to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   Filename filelist pipe "dir /b /s c:\temp\*.csv"; 
                                                                                   
   Data myFileList;                                        
     Infile filelist truncover;
     Input filename $256.;
   Run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jul 2019 16:45:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-22T16:45:47Z</dc:date>
    <item>
      <title>Pulling files from an output folder without knowing the file names and merging them into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575446#M162777</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to pull multiple files from an output folder where each are in this format; SUBJECTXXX_datetime.csv. So each folder has a different Subject ID and a different date stamp. There can multiple files in this one folder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to pull all the files that are in this folder into SAS and merge them into one dataset, but I am unsure how to do this without calling each file individually. Once those files are in that one dataset, I'd like to move them to another folder, to then run my program again for the next batch of files&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help, thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 16:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575446#M162777</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T16:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575447#M162778</link>
      <description>You can read all files at once or read each folder at a time. First you need to create a list of the files and a working program to read one file. &lt;BR /&gt;Do you have either of those? Once you do, making it happen for every file is a pretty trivial task &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 22 Jul 2019 16:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575447#M162778</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-22T16:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575448#M162779</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not have that in my program yet, I was not sure how to call all the files without having to name them all individually.&lt;/P&gt;&lt;P&gt;Is there a good way of doing that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had found this online:&lt;/P&gt;&lt;PRE&gt;   %include "&amp;amp;dir\&amp;amp;name" /source2;&lt;/PRE&gt;&lt;PRE&gt;   Filename filelist pipe "dir /b /s c:\temp\*.sas"; 
                                                                                   
   Data _null_;                                        
     Infile filelist truncover;
     Input filename $100.;
     Put filename=;
   Run; &lt;/PRE&gt;&lt;P&gt;Would that work well for what I need to do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I can merge them without calling them separately as well?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 16:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575448#M162779</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T16:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575449#M162780</link>
      <description>&lt;P&gt;You can read all of the files in one data step if you want.&lt;/P&gt;
&lt;P&gt;Use a wildcard in the INFILE statement to select the files that match the pattern.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the FILENAME= option on the INFILE statement to have SAS store the actual file name into a variable.&lt;/P&gt;
&lt;P&gt;You will need to copy the filename to a new variable if you want to keep the filename as the variable named in the INFILE statement is not kept.&lt;/P&gt;
&lt;P&gt;If you files have header rows then you can test when the file name changes to know when to skip the header row.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  length fname $200;
  infile "&amp;amp;mdir/*.csv" dsd truncover filename=fname ;
  input @;
  if fname ne lag(fname) then input;
  length subject $10 datetime $10 ;
  fname = scan(fname,-1,'/\');
  subject=scan(fname,1,'_');
  datetime=scan(fname,2,'_.');
  .... rest of code to read the actual data ...
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 16:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575449#M162780</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-22T16:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575453#M162783</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139341"&gt;@kmardinian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not have that in my program yet, I was not sure how to call all the files without having to name them all individually.&lt;/P&gt;
&lt;P&gt;Is there a good way of doing that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had found this online:&lt;/P&gt;
&lt;PRE&gt;   %include "&amp;amp;dir\&amp;amp;name" /source2;&lt;/PRE&gt;
&lt;PRE&gt;   Filename filelist pipe "dir /b /s c:\temp\*.sas"; 
                                                                                   
   Data _null_;                                        
     Infile filelist truncover;
     Input filename $100.;
     Put filename=;
   Run; &lt;/PRE&gt;
&lt;P&gt;Would that work well for what I need to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then I can merge them without calling them separately as well?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would modify it to save it to a data set - check that it lists all the files you need and not the directories.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to filter it if you have other files in the same folder.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason I'm not suggesting wildcards, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; is, is because you have files in multiple folders and I don't think wildcards can handle that without multiple calls. And I'm assuming by 'merging' you mean append and add in the subject name as a field rather than merge to a wide data set because that doesn't makes sense to me. You can use his approach and repeat it several times or you can find all the file names and read them into a single data set in one step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The infile documentation has some examples but once you provide the code to read a single file we can help you convert it to the code you need to read all files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check that this gives you the file list with all the files you need to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   Filename filelist pipe "dir /b /s c:\temp\*.csv"; 
                                                                                   
   Data myFileList;                                        
     Infile filelist truncover;
     Input filename $256.;
   Run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 16:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575453#M162783</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-22T16:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575455#M162785</link>
      <description>&lt;P&gt;If ALL of the files in a folder that start with SUBJECT and have the same layout then this is not that hard. The key bit is ALL. If you want not to read some that start with SUBJECT or any of them have different file layouts then this gets more complicated.&lt;/P&gt;
&lt;P&gt;Do you have a working data step to read one of these files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following is a skeleton of reading a bunch of CSV files that have one header row in each;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data dummy;
   infile "&amp;lt;path&amp;gt;\subject*.csv" dsd lrecl=32767 firstobs=2 eov=skip;
   /*&amp;lt;informat or attribute statement(s) of variables&amp;gt;*/
   input @;
   if skip=1 then skip=0;
   else do;
     input
     /* variable list*/
     end;
     /* other code wanted*/
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;The firstobs=2 skips a header row for the first file. The Option EOV sets a variable, named skip in this example, to 1 when the first file in a series is read.&lt;/P&gt;
&lt;P&gt;The input @. is basically to set the skip value and have it for testing. If it is equal to 1 we do not want to read that line. Because the value would only change on reading we set to 0 for the next iteration of the step. The actual input is in a DO End loop with an OUTPUT statement as we don't want output when encountering a header row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have more than one header row then you need a different value for FIRSTOBS and an instruction to read past the header such as the following to read past a second header row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if skip then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; skip=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; input;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 16:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575455#M162785</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-22T16:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575468#M162795</link>
      <description>&lt;P&gt;I was able to read in each file with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let path1=C:\Users\K.M\Desktop\Reads\;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;libname path1 "&amp;amp;path1";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let dir=&amp;amp;path1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;filename xlfile pipe "dir ""&amp;amp;dir"" /tc /a-d" lrecl=200;&lt;/P&gt;&lt;P&gt;data in;&lt;BR /&gt;infile xlfile length=len end = eof;&lt;BR /&gt;input char $varying400. len;&lt;BR /&gt;if index(char,'.csv');&lt;BR /&gt;filename=scan(char,5,' ');&lt;BR /&gt;if filename =:'SUBJECT-';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now I have an output dataset with the variables char and filename. So now I have to figure out how to use the variable filename to call each file so I can merge them into one dataset. Is there a good way of doing this?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 17:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575468#M162795</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T17:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575472#M162799</link>
      <description>Do you have the code to read a single file? I'll help you put them together once you post that code.</description>
      <pubDate>Mon, 22 Jul 2019 17:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575472#M162799</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-22T17:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575476#M162802</link>
      <description>&lt;P&gt;So if you have a dataset named IN with a variable named CHAR that has the name of the file to read then you can use that to drive reading all of the files in one step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set in ;
  fname=char ;
  infile csv filevar=fname dsd firstobs=2 truncover end=eof;
  do while (not eof);
    ... code to read the data from a line ...
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 17:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575476#M162802</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-22T17:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575505#M162815</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't quite understand how this code will import all of the individual files one by one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And what do you mean by this line "&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; code to read the &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; a line &lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Kristina&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 17:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575505#M162815</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T17:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575514#M162819</link>
      <description>&lt;PRE&gt;data want ;
  set in ; &lt;FONT color="#008000"&gt;&lt;STRONG&gt;*data set with list of file names and paths to read in;&lt;/STRONG&gt;&lt;/FONT&gt;

&lt;FONT color="#008000"&gt;&lt;STRONG&gt; *store filename so you can get information later;&lt;/STRONG&gt;&lt;/FONT&gt;
  fname=char ;


  infile csv filevar=fname dsd firstobs=2 truncover end=eof; &lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;*note fname is used here as filevar, which controls which file is read;
*note eof which says that its the end of a file and avoids reading first line of new file;&lt;/FONT&gt;&lt;/STRONG&gt;

  do while (not eof);
   &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt; INPUT tested input data statement to read your file;&lt;/FONT&gt;&lt;/STRONG&gt;
    output;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 18:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575514#M162819</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-22T18:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575515#M162820</link>
      <description>&lt;P&gt;The main data step will read in the dataset with the file names one observation at a time.&lt;/P&gt;
&lt;P&gt;It then tells the INFILE statement which variable contains the NAME of the file to read.&amp;nbsp; It also tells the INFILE statement to skip the first line of the file (assuming your files have a header row) and set the variable EOF to be true when it has read the last line from that file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DO loop will then let you read each line from the file.&amp;nbsp; You will need to have a explicit OUTPUT statement since each iteration of the data step will read an entire file and not just one observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I left out the part about how to read the data from the files since you did not supply the information needed to do that.&amp;nbsp; In general it is trivial to write code to read from a delimited file. First define the variable (easiest if you define them in the order they appear in the file). The assign any NEEDED informats or WANTED formats using INFORMAT and/or FORMAT statement. Then read the line using an INPUT statement.&amp;nbsp; Simple example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length id $20 age 8 dob 8 class $20 ;
informat dob date.;
format dob date9.;
input id -- class;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 18:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575515#M162820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-22T18:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575521#M162825</link>
      <description>&lt;P&gt;I'm sorry for not understanding this clearly. But the do loop only needs to include an input statement listing all the variables in the files?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 18:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575521#M162825</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T18:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575522#M162826</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You mentioned like Reeza that I have failed to supply the information needed to read in the data. What information do you need for that exactly? A proc import statement or an infile statement? Isn't that already in my line of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 18:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575522#M162826</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T18:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575526#M162827</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139341"&gt;@kmardinian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You mentioned like Reeza that I have failed to supply the information needed to read in the data. What information do you need for that exactly? A proc import statement or an infile statement? Isn't that already in my line of code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't want to use PROC IMPORT to read multiple delimited files. It will guess at how to define the variables based on the limited sample of data that appears in the one file it is currently processing. So you will end up with incompatible datasets.&amp;nbsp; Plus you will need to run a separate PROC step for each individual file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You did not supply any INPUT statements (or other code) to read ANY of the files.&amp;nbsp; You did supply code to get the LIST of files, so that is why I said start with the dataset that has the list of files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of a program that reads delimited data. I will use in-line data using | as the delimiter to make the example clearer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile cards dsd dlm='|' truncover firstobs=2;
  length name $20 age 8 dob 8 class&amp;nbsp;$20&amp;nbsp;;
&amp;nbsp;&amp;nbsp;informat&amp;nbsp;dob&amp;nbsp;date.;
&amp;nbsp;&amp;nbsp;format&amp;nbsp;dob&amp;nbsp;date9.;
  input name -- class;
cards;
Name|Age|DOB|Class
Fred|20|01JAN1999|Computer&amp;nbsp;Science
Jill|23|02-JAN-1997|Mathematics
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have many files all in the same format then you should have somewhere a document that describes the order of the fields and definition of each field.&amp;nbsp; Use that to help you write the code. If you don't have such a document then try running PROC IMPORT on just one of the files and look at the code it generates. It will be ugly with many unneeded (unwanted) formats and informats attached to the variables, but it should let you have a starting point. You will also want to perhaps pad the lengths of any character variables in case future files have longer values.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 18:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575526#M162827</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-22T18:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575558#M162834</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139341"&gt;@kmardinian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm sorry for not understanding this clearly. But the do loop only needs to include an input statement listing all the variables in the files?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should have the Length or Format statements as indicated by Tom, but it's why I've said from the start you need two things to automate this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. File list -&amp;gt; now solved&lt;/P&gt;
&lt;P&gt;2. Working code to read one file, via a data step -&amp;gt; outstanding&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code to read the single file, whether it includes INFORMATS, FORMATS, LENGTH statements, must include an INPUT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So within that do loop you place the code you've tested as working to read the file. I would start by limiting your input data set and testing it, add the obs=4 to the SET statement to test it out on a small set of files first. Once it's working, remove that option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set in (obs=4);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2019 19:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575558#M162834</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-22T19:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575566#M162835</link>
      <description>&lt;P&gt;Is there anyway that I can just ask SAS to spit out all the variables without listing their individual lengths and formats. I have over 50 variables in each of these files, so I was able to copy and paste them all into the input statement but writing out each length and format would be super tedious.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, it does not seem to be recognizing my file path for some reason.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;55&lt;BR /&gt;56 data want ;&lt;BR /&gt;57 set in ;&lt;BR /&gt;58 fname=filename ;&lt;BR /&gt;59 infile xlfile filevar=fname dsd firstobs=2 truncover end=eof;&lt;BR /&gt;60 do while (not eof);&lt;BR /&gt;61&lt;BR /&gt;62 input studyID study Date readID&amp;nbsp; --------------------------------------------------------------------- ;&lt;BR /&gt;63&lt;BR /&gt;64 output;&lt;BR /&gt;65 end;&lt;BR /&gt;66 run;&lt;/P&gt;&lt;P&gt;ERROR: Physical file does not exist, C:\SAS\Config\Lev1\SASApp\STAR-SUBJECT07.csv.&lt;BR /&gt;char=07/22/2019 01:06 PM 2,116 STAR-SUBJECT07.csv filename=STAR-SUBJECT07.csv num=1 fname=STAR-SUBJECT07.csv&lt;BR /&gt;eof=0 studyID=. study=. Date=. readID=. _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: There were 1 observations read from the data set WORK.IN.&lt;BR /&gt;WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 7 variables.&lt;BR /&gt;WARNING: Data set WORK.WANT was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 19:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575566#M162835</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T19:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575569#M162836</link>
      <description>&lt;P&gt;Make sure that FNAME has the FULL name of the file. Your error message is saying you did not provide the path that the file lives in.&amp;nbsp; If it is not in your source file list then add it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FNAME='my directory name/' || filename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of the files have the same data in the same order right???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;50 variables is NOTHING.&lt;/P&gt;
&lt;P&gt;Copy the first line from one of the files and paste it into the editor and convert it into a LENGTH statement.&lt;/P&gt;
&lt;P&gt;Replicate those that you might need to use for FORMAT or INFORMAT statement.&lt;/P&gt;
&lt;P&gt;For the INPUT statement you just need to list the FIRST and LAST variable name with double hyphen to specify a positionally defined variable list.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 20:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575569#M162836</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-22T20:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575590#M162847</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139341"&gt;@kmardinian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there anyway that I can just ask SAS to spit out all the variables without listing their individual lengths and formats. I have over 50 variables in each of these files, so I was able to copy and paste them all into the input statement but writing out each length and format would be super tedious.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is tedious but really the only way to ensure your data is read correctly. And honestly, it'll save you time to figure it out all now, rather than later when you realize that three variables were truncated so that's why your numbers are all off.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 20:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575590#M162847</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-22T20:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling files from an output folder without knowing the file names and merging them into a datas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575597#M162849</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the filename in my first output dataset and they match exactly to the full name of each file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created this macro variable for where the files are located. Am I not calling it correctly in my code because I then get this error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let path1=C:\Users\Kristina.Mardinian\Desktop\Reads\;&lt;BR /&gt;libname path1 "&amp;amp;path1";&lt;/P&gt;&lt;P&gt;%let dir=&amp;amp;path1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;55&lt;BR /&gt;56 data want ;&lt;BR /&gt;57 set in ;&lt;BR /&gt;58 fname=filename ;&lt;BR /&gt;59 infile "&amp;amp;dir/" filevar=fname dsd dlm='|' firstobs=2 truncover end=eof;&lt;BR /&gt;ERROR: A Physical file reference (i.e. "PHYSICAL FILE REFERENCE" ) or an aggregate file storage reference (i.e. AGGREGATE(MEMBER) )&lt;BR /&gt;reference cannot be used with the FILEVAR= option.&lt;BR /&gt;60 do while (not eof);&lt;BR /&gt;61&lt;BR /&gt;62 input studyID study Date readID ;&lt;BR /&gt;63&lt;BR /&gt;64 output;&lt;BR /&gt;65 end;&lt;BR /&gt;66 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2019 21:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-files-from-an-output-folder-without-knowing-the-file/m-p/575597#M162849</guid>
      <dc:creator>kmardinian</dc:creator>
      <dc:date>2019-07-22T21:18:54Z</dc:date>
    </item>
  </channel>
</rss>

