<?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 the file names and create a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226236#M40711</link>
    <description>&lt;P&gt;Make sure that the OUTPUT; statement is not inside a conditional block.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2015 10:59:21 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2015-09-18T10:59:21Z</dc:date>
    <item>
      <title>Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225338#M40431</link>
      <description>&lt;P&gt;My requirement is to read the file names from dataset and create a master dataset by appending all the files. I 've tried this via follow code, but could not succeed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would request someone to guide me to complete this task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading the filenames as below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dirlist;
  infile cards truncover;
  input file_names $300.;
  cards;
'/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/SASApp_STPServer_2015-08-30_tmptcmlva2_191​42.log'
'/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/SASApp_STPServer_2015-08-29_tmptcmlva2_191​42.log'
'/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/SASApp_STPServer_2015-08-28_tmptcmlva2_191​42.log'
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to read and append all the files&amp;nbsp;to create one master dataset. So I wrote a code as below. However, I could &amp;nbsp;not succeeed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems there was some error in my either infile statement or do loop which I'm unable to figure out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA output_data_set;
set dirlist;
/* read the file references in variable called file_names */
INFILE  IN dsd truncover FILEVAR = file_names END = end_of_file LRECL=32000;
     DO WHILE (end_of_file = 0);
        input var : $ 3000.;
/*filename=file_names;*/
var1 = _infile_;
if var1 = :'201';
Date_TimeStamp= scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;
        OUTPUT;
     END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;There are records in my input files,but my code could not read it for some reasons. Please guide me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;4          data dirlist;
5            infile cards truncover;
6            input file_names $300.;
7            cards;

NOTE: The data set WORK.DIRLIST has 3 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds
      

7        !         
11         ;
12         run;
&amp;#12;2                                                          The SAS System                           08:36 Friday, September 11, 2015

13         
14         DATA output_data_set;
15         set dirlist;
16         /* read the file references in variable called file_names */
17         INFILE  IN dsd truncover FILEVAR = file_names END = end_of_file LRECL=32000;
18              DO WHILE (end_of_file = 0);
19                 input var : $ 3000.;
20         /*filename=file_names;*/
21         var1 = _infile_;
22         if var1 = :'201';
23         Date_TimeStamp= scan(var1,1," ");
24         Status = scan(var1,2," ");
25         Processid = scan(var1,3," ");
26         userid = scan(var1,4," ");
27         Details = scan(var1,-1,'-');
28         drop var var1;
29                 OUTPUT;
30              END;
31         RUN;

NOTE: The variable file_names exists on an input data set, but was also specified in an I/O statement option.  The variable will 
      not be included on any output data set.
NOTE: The infile IN is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredPro​cessServer/Logs/SASApp_STPServer_2015-08-30_tmptcm​lva2_19142.log,
      
      File List=('/usr/sas/sas_config/Lev1/SASApp/StoredProce​ssServer/Logs/SASApp_STPServer_2015-08-30_tmptcmlv​a2_19142.log' 
      '/apps/tir/test/loganalysis/
'),
      Owner Name=sassrv,Group Name=sas,
      Access Permission=rwxrwxr-x,
      Last Modified=Mon Aug 31 00:01:56 2015,
      File Size (bytes)=720559

NOTE: The infile IN is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredPro​cessServer/Logs/SASApp_STPServer_2015-08-29_tmptcm​lva2_19142.log,
      
      File List=('/usr/sas/sas_config/Lev1/SASApp/StoredProce​ssServer/Logs/SASApp_STPServer_2015-08-29_tmptcmlv​a2_19142.log' 
      '/apps/tir/test/loganalysis/
'),
      Owner Name=sassrv,Group Name=sas,
      Access Permission=rwxrwxr-x,
      Last Modified=Sun Aug 30 00:01:46 2015,
      File Size (bytes)=720559

NOTE: The infile IN is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredPro​cessServer/Logs/SASApp_STPServer_2015-08-28_tmptcm​lva2_19142.log,
      
      File List=('/usr/sas/sas_config/Lev1/SASApp/StoredProce​ssServer/Logs/SASApp_STPServer_2015-08-28_tmptcmlv​a2_19142.log' 
      '/apps/tir/test/loganalysis/
'),
      Owner Name=sassrv,Group Name=sas,
      Access Permission=rwxrwxr-x,
      Last Modified=Sat Aug 29 00:01:36 2015,
      File Size (bytes)=2815408

NOTE: 1 record was read from the infile IN.
      The minimum record length was 572.
      The maximum record length was 572.
NOTE: 1 record was read from the infile IN.
      The minimum record length was 572.
      The maximum record length was 572.
&amp;#12;3                                                          The SAS System                           08:36 Friday, September 11, 2015

NOTE: 1 record was read from the infile IN.
      The minimum record length was 572.
      The maximum record length was 572.
NOTE: There were 3 observations read from the data set WORK.DIRLIST.
NOTE: The data set WORK.OUTPUT_DATA_SET has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.00 seconds&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Sep 2015 06:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225338#M40431</guid>
      <dc:creator>RamKumar</dc:creator>
      <dc:date>2015-09-14T06:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225369#M40446</link>
      <description>&lt;P&gt;Could you clarify your request. &amp;nbsp;Do you want to create a dataset with the contents of the three files, if so why not use a wildcard approach:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/*.log";&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have to be specific then maybe:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set dirlist;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('data inter; infile "'||strip(file_names)||'"; ....otherbits of code...; run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then call execute('data base; set inter; run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp; else call execute('proc datasets library=work nolist;&amp;nbsp;base=your_base_file data=inter force; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 13:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225369#M40446</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-09-14T13:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225371#M40448</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having some difficulties using this new forum. &amp;nbsp;For your question, is there a reason why you do not use the wildcard:&lt;/P&gt;&lt;P&gt;data xyz;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/*.log";&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or maybe if you need to be specific:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set dir_list;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('data inter; infile "'||strip(file_names)||'"; ...other code...; run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then call execute('data base; set inter; run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp; else call execute('proc datasets library=work nolist; base=base data=inter force; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 13:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225371#M40448</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-09-14T13:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225383#M40450</link>
      <description>&lt;P&gt;Does your code work for one file? What is your program for a single file that works?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 15:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225383#M40450</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-14T15:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225394#M40453</link>
      <description>&lt;P&gt;Change&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;DO WHILE &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;end_of_file &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;to&lt;BR /&gt;DO WHILE(NOT end_of_file);&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Sep 2015 16:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225394#M40453</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-09-14T16:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225414#M40458</link>
      <description>&lt;P&gt;This might be the culprit causing no output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 = :'201';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Sep 2015 17:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225414#M40458</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-09-14T17:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225432#M40461</link>
      <description>&lt;P&gt;Yes that is it. &amp;nbsp;A subsetting IF is breaking out of the DO WHILE(NOT EOF) loop and sending the program back to read another file and on and on.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 19:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/225432#M40461</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-09-14T19:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226039#M40645</link>
      <description>&lt;P&gt;After applying your advise I slightly tweaked my code&amp;nbsp;with macro, but again I end up with other error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, I've the file names in output_file.txt and I reading it to create a dataset. Please be informed I need to create a dataset only if file name (part of file name) matches. My management want me to develop with this code via macro and hence I used macro in my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output_file.txt has&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fname&amp;nbsp;&amp;nbsp; /*header*/&lt;/P&gt;&lt;P&gt;SASApp_STPServer_2015-09-15_tmptcmsaslva2_18208.log&lt;BR /&gt;SASApp_STPServer_2015-09-15_tmptcmsaslva2_19142.log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname log '/usr/sas/tir/test/loganalysis/';

proc import datafile='/usr/sas/tir/test/loganalysis/output_file.txt'
            out=log.output_file
            dbms=dlm
                        replace;
	    delimiter='09'x;
run;

Options symbolgen mlogic mprint mfile; 
%macro log_analysis;

%let filedate=%sysfunc(putn("&amp;amp;sysdate9"d-2,yymmdd10.));
%put &amp;amp;filedate;

data log.log_analysis;
length fname filename $200;
infile "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_&amp;amp;filedate._tmptcmsaslva2_*.log" dsd truncover FILEVAR = file_names END = end_of_file LRECL=32000;
DO WHILE (not end_of_file);
input var : $ 3000.;
/*filename=fname;*/
var1 = _infile_;
if var1 = :'201';
Date_TimeStamp= scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;
output;
end;
run;

mend log_analysis;


data _null_;
  set log.output_file;
  if fname =: 'SASApp_STPServer' then call execute ('%log_analysis;');
else put 'no log files';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piece of log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1         + data log.log_analysis;  length fname filename $200;  infile 
"/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_*.log" dsd truncover FILEVAR = 
file_names END = end_of_file LRECL=32000;  DO WHILE (not
ERROR: A Physical file reference (i.e. "PHYSICAL FILE REFERENCE" ) or an aggregate file storage reference (i.e. AGGREGATE(MEMBER) ) 
       reference cannot be used with the FILEVAR= option.&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;I request&amp;nbsp;someone to help me to come past this error.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 12:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226039#M40645</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-17T12:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226041#M40646</link>
      <description>&lt;P&gt;In your data step within the macro, you specify&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filevar = file_names&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This means that file_names must contain the physical name of the infile to be read. Since you do not assign a value to file_names anywhere in the data step, this fails.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 12:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226041#M40646</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-09-17T12:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226048#M40648</link>
      <description>The error message is pretty clear. You cannot code INFILE 'myfile' FILEVAR=myfilenamevar ... since you are giving it the physical name in two places. Replace the quoted filename with a dummy fileref. INFILE dummy FILEVAR=myfilenamevar ... ;</description>
      <pubDate>Thu, 17 Sep 2015 13:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226048#M40648</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-17T13:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226195#M40689</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I replaced my infile statement as follows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile dummy dsd truncover FILEVAR = file_names END = end_of_file LRECL=32000;&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;Got error as follows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Variable fname is uninitialized.
NOTE: Variable filename is uninitialized.
ERROR: Invalid physical name.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question,&amp;nbsp; how SAS will recongnize that&amp;nbsp;the file reference 'dummy' is the file names to be read from the dataset &lt;SPAN class="token function"&gt;&lt;FONT color="#0000ff"&gt;log&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;.&lt;/FONT&gt;&lt;/SPAN&gt;output_file. Please be informed that there is only the filename in the dataset &lt;SPAN class="token function"&gt;&lt;FONT color="#0000ff"&gt;log&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;.&lt;/FONT&gt;&lt;/SPAN&gt;output_file. There is no path in the dataset or anywhere in the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly guide me where should I mention the path in the program which makes life easier. Just I need to know whether the&amp;nbsp; file &lt;FONT color="#000000"&gt;output_fil​e.txt should have the path along with file names or I should mention in infile statement which is under the macro.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I would request you to see my previous post to understand the files and other stuffs.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thanks&amp;nbsp; for the inputs so far.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 06:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226195#M40689</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-18T06:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226198#M40690</link>
      <description>&lt;P&gt;When you use the &lt;FONT face="courier new,courier"&gt;filevar=&lt;EM&gt;any_variable_name&lt;/EM&gt;&lt;/FONT&gt; construct in a INFILE&amp;nbsp;statement, you MUST provide a valid physical filename in the variable &lt;EM&gt;&lt;FONT face="courier new,courier"&gt;any_variable_name&lt;/FONT&gt;&lt;/EM&gt; before you can read from the infile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to read data from a certain set of similarly structured external files in one data step, you best create a SAS dataset with the filenames and do something like that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
* code that reads filenames into the variable file_names;
run;

data want;
infile dummy filevar=file_names end=end_of_file /* other options */;
set have;
do while (not end_of_file);
&amp;nbsp; input /* list of variables */;
  * further processing;
&amp;nbsp; 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;</description>
      <pubDate>Fri, 18 Sep 2015 07:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226198#M40690</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-09-18T07:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226205#M40691</link>
      <description>&lt;P&gt;Still I had trouble reading the files. I did tried as you said, but I got error like 'ERROR: Invalid physical name'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output_file.txt has records like, (fname is a header)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fname&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_18208.log&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_19142.log&lt;/P&gt;&lt;P&gt;'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname log '/usr/sas/tir/test/loganalysis/';

proc import datafile='/usr/sas/tir/test/loganalysis/output_file.txt'
            out=log.output_file
            dbms=dlm
                        replace;
	    delimiter='09'x;
run;


Options symbolgen mlogic mprint mfile; 

%macro log_analysis;

%let filedate=%sysfunc(putn("&amp;amp;sysdate9"d-3,yymmdd10.));
%put &amp;amp;filedate;

data log.log_analysis;
length fname $200;
infile dummy dsd truncover FILEVAR = fname END = end_of_file LRECL=32000;
DO WHILE (not end_of_file);
input var : $ 3000.;
/*filename=fname;*/
var1 = _infile_;
if var1 = :'201';
Date_TimeStamp= scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;
output;
end;
run;

%mend log_analysis;

data _null_;
  set log.output_file;
  if fname =: '/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer' then call execute ('%log_analysis;');
else put 'no log files';
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 08:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226205#M40691</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-18T08:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226211#M40694</link>
      <description>&lt;P&gt;Babloo, take a good look at this part of you code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data log.log_analysis;
length fname $200;
infile dummy dsd truncover FILEVAR = fname END = end_of_file LRECL=32000;
DO WHILE (not end_of_file);
input var : $ 3000.;
/*filename=fname;*/
var1 = _infile_;
if var1 = :'201';
Date_TimeStamp= scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then tell me: WHERE DO YOU SET fname???&lt;/P&gt;&lt;P&gt;Answer: nowhere. That's why it does not work.&lt;/P&gt;&lt;P&gt;The fact that fname is present in the data step that creates code through call execute does in no way imply that the variable somehow magically appears in the generated code (which is executed AFTER the data step doing the call execute has ended). You have to provide for some mechanism to get the filenames into your main step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I feel&amp;nbsp;you are thinking way too complicated here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My immediate solution would look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- create a data step to read one single log file into an intermediate file&lt;/P&gt;&lt;P&gt;- wrap that in a macro definition that accepts the input filename as a parameter, and has a second step appending&amp;nbsp;the data&amp;nbsp;to a base file&lt;/P&gt;&lt;P&gt;- call that macro in a data step that reads the input filenames; every iteration will add another log output to your base file-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 08:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226211#M40694</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-09-18T08:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226212#M40695</link>
      <description>&lt;P&gt;You are making it much too complicated. As someone said above the main error is that you cannot use a subsetting IF statement because that will break out of the DO WHILE loop and terminate the processing of the current file.&amp;nbsp; You need to use IF/THEN/DO/END instead to conditionally execute the OUTPUT statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You probably should add some LENGTH or ATTRIB statements to define the variables that you are scanning from the lines in the log file.&amp;nbsp; As the code is currently written they will all be character length 3000 since they are derived from string operations on VAR1 which is defaulting to the same because of the format used on the INPUT statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=/usr/sas/tir/test/loganalysis ;

libname log "&amp;amp;path/";

data log.output_file ;
  infile "&amp;amp;path/output_file.txt" firstobs=2 truncover ;
  input fname $200. ;
run;

data log.log_analysis;
  set log.output_file ;
  filename=fname;
  infile dummy dsd truncover filevar = fname end = end_of_file lrecl=32000;
  do while (not end_of_file);
    input var1 $3000.;
    if var1 = :'201' then do;
      Date_TimeStamp= scan(var1,1," ");
      Status = scan(var1,2," ");
      Processid = scan(var1,3," ");
      userid = scan(var1,4," ");
      Details = scan(var1,-1,'-');
      output;
    end;
  end;
  drop var1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 08:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226212#M40695</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-18T08:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226218#M40697</link>
      <description>&lt;P&gt;I've trouble understanding your suggestions since I'm a novice user. However,&amp;nbsp;I tried&amp;nbsp; your code as like below, but still i could not succeed. This time there was no error either. Instead the code failed to read records from the infiles although there was a records in one of the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aplogies for testing for patience. I can understand if someone can tweak my code&amp;nbsp;to work in such a way as&amp;nbsp;I excepted instead of writing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate all your efforts so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname log '/usr/sas/tir/test/loganalysis/';

Options symbolgen mlogic mprint mfile; 

%let path=/usr/sas/tir/test/loganalysis ;

libname log "&amp;amp;path/";

data log.output_file ;
  infile "&amp;amp;path/output_file.txt" firstobs=2 truncover ;
  input fname $400. ;
run;


%macro log_analysis;

%let filedate=%sysfunc(putn("&amp;amp;sysdate9"d-3,yymmdd10.));
%put &amp;amp;filedate;

data log.log_analysis;
set log.output_file;
filename=fname;
length fname $400;
infile dummy dsd truncover FILEVAR = fname END = end_of_file LRECL=32000;
DO WHILE (not end_of_file);
input var : $ 3000.;
/*filename=fname;*/
var1 = _infile_;
if var1 = :'201';
Date_TimeStamp= scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;
output;
end;
run;

%mend log_analysis;

data _null_;
  set log.output_file;
  if fname =: '/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer' then call execute ('%log_analysis;');
else put 'no log files';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piece of log:&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;NOTE: The infile DUMMY is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_18208.log,
       Access Permission=rwxrwxr-x,
      Last Modified=Thu Sep 17 03:57:47 2015,
      File Size (bytes)=1831

NOTE: The infile DUMMY is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_19142.log,
      Access Permission=rwxrwxr-x,
      Last Modified=Tue Sep 15 23:57:49 2015,
      File Size (bytes)=2254685

NOTE: 1 record was read from the infile DUMMY.
      The minimum record length was 572.
      The maximum record length was 572.
NOTE: 1 record was read from the infile DUMMY.
      The minimum record length was 572.
      The maximum record length was 572.
NOTE: There were 2 observations read from the data set LOG.OUTPUT_FILE.
NOTE: The data set LOG.LOG_ANALYSIS has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ouput_file.txt has records like,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fname&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_18208.log&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_19142.log&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 09:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226218#M40697</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-18T09:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226220#M40698</link>
      <description>&lt;P&gt;This is the subsetting IF statement that for some reason you keep adding back to the program.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 = :'201';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What this means is :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 = :'201' THEN RETURN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So when your program read the first line of each file and saw that they did not start with the letters '201' it went back to the top of the data step and started reading the next file. That is why only one line was read from each file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead you want to write an IF/THEN/DO loop so that you can conditionally process each line of the file without leaving the DO WHILE loop.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 = :'201' THEN DO;
  .... code to execute conditionally goes here ...
END;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 09:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226220#M40698</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-18T09:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226228#M40703</link>
      <description>&lt;P&gt;When debugging these kinds of problems, start with a simple step that just reads all lines into a variable (what you already do with var) and avoid any further processing beyond the absolutely necessary output; statement. Once that works, add code until you're either finished or something unexpected happens; in this case you will have a clue what caused this.&lt;/P&gt;&lt;P&gt;Don't try to solve everything at once, work towards your goal in easily controllable steps; right now you are doing too much too quickly, which then overwhelms your still limited capacity (after all, you're just a beginner, nothing wrong with that) to discern where the problem might be.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 10:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226228#M40703</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-09-18T10:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226231#M40706</link>
      <description>&lt;P&gt;Excellent, code works like a charm after I modified my if clause as you said, however i do have other questions on total number of observations in log.log_analysis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would except atleast 9+18702=18711 records in the datset log.log_analysis. Any&amp;nbsp;thoughts why I got less observations when compared to the required observations?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The infile DUMMY is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_18208.log,
      Access Permission=rwxrwxr-x,
      Last Modified=Thu Sep 17 03:57:47 2015,
      File Size (bytes)=1831

NOTE: The infile DUMMY is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-15_tmptcmsaslva2_19142.log,
      Access Permission=rwxrwxr-x,
      Last Modified=Tue Sep 15 23:57:49 2015,
      File Size (bytes)=2254685

NOTE: 9 records were read from the infile DUMMY.
      The minimum record length was 107.
      The maximum record length was 572.
NOTE: 18702 records were read from the infile DUMMY.
      The minimum record length was 66.
      The maximum record length was 572.
NOTE: There were 2 observations read from the data set LOG.OUTPUT_FILE.
NOTE: The data set LOG.LOG_ANALYSIS has 18705 observations and 6 variables.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 10:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226231#M40706</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-18T10:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read the file names and create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226234#M40709</link>
      <description>&lt;P&gt;I've a other question now, how to code to look for the next file and create a SAS dataset&amp;nbsp;when the first file is in use. When I tried reading other log files, I got error as follows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: File is in use, /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-11_tmptcmsaslva2_29115.log.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output_file.txt has,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fname&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-11_tmptcmsaslva2_29115.log&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-11_tmptcmsaslva2_18208.log&lt;BR /&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-11_tmptcmsaslva2_19142.log&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 10:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-the-file-names-and-create-a-dataset/m-p/226234#M40709</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-18T10:55:52Z</dc:date>
    </item>
  </channel>
</rss>

