<?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: How do i read Multiple log files from a path having incremental version number to a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890067#M351680</link>
    <description>&lt;P&gt;The macro is not generating the right code.&lt;/P&gt;
&lt;P&gt;But you don't need macro logic to read 17 different files in a data step.&amp;nbsp; Just data step logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pathname=some direcotry/;
%let file=some prefix;
%let ver=17;


data chk_lst;
  length ver 8 fname $50 filename $256 lineno 8 line $900;
  do ver=1 to &amp;amp;ver ;
    fname=cats("&amp;amp;file",ver);
    filename=cats("&amp;amp;pathname",fname);
    infile logfile filevar=filename end=eof truncover;
    do lineno=1 by 1 while (not eof);
      input line $char900.;
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 19 Aug 2023 20:01:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-19T20:01:59Z</dc:date>
    <item>
      <title>How do i read Multiple log files from a path having incremental version number to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/889861#M351597</link>
      <description>&lt;P&gt;I Am trying to read all the log files of a user to a dataset having incremental number version .&lt;/P&gt;&lt;P&gt;Please check below example.&lt;/P&gt;&lt;P&gt;I am SAS 9.4 , trying to extract all the log files of user1 having 17 versions into dataset chkmain.&lt;/P&gt;&lt;P&gt;I tried below code, the iterations are working but not getting observations into dataset. Pease suggest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro version(file=,ver=);&lt;BR /&gt;data chk_lst;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i= 1 %to &amp;amp;ver ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;infile "&amp;amp;pathname&amp;amp;file&amp;amp;i"&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lrecl=900 termstr=CRLF delimiter=' ' truncover;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input f_1$1-900;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend;&lt;BR /&gt;%version(file=user1.log@@/main/,ver=17);&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 13:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/889861#M351597</guid>
      <dc:creator>Ramag</dc:creator>
      <dc:date>2023-08-18T13:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do i read Multiple log files from a path having incremental version number to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/889893#M351600</link>
      <description>&lt;P&gt;Usual advice is to try getting the code working first without macros.&amp;nbsp; It will be easier to debug.&amp;nbsp; Then after it's working without macros (reading says 3 log files), then go back to working on a macro solution.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make a single fileref that points to multiple files, and use a single INFILE statement in your DATA step to read data from all the files, like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mylogs ("Q:\junk\log1.log" "Q:\junk\log2.log") ;
data _null_ ;
  infile mylogs ;
  input ;
  put _infile_ ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you can get a step like that working, then your macro is simpler to write, because it only needs to generate the list of file names.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 14:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/889893#M351600</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-18T14:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do i read Multiple log files from a path having incremental version number to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890019#M351651</link>
      <description>&lt;P&gt;Did you consider using a wildcard?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let log_path=c:\temp;
%let log_rootname=mylog;

data work.want;
  length _fname $400 log_name $80 line_num 8;
  infile "&amp;amp;log_path\&amp;amp;log_rootname.*.log" truncover filename=_fname;
  input logline $char256.;
  log_name=scan(_fname,-1,'\/');
  if lag(log_name) ne log_name then line_num=1; else line_num+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2023 02:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890019#M351651</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-19T02:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do i read Multiple log files from a path having incremental version number to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890036#M351663</link>
      <description>&lt;P&gt;What does the log say?&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 07:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890036#M351663</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-19T07:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do i read Multiple log files from a path having incremental version number to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890037#M351664</link>
      <description>&lt;P&gt;You use slashes for the path, indicating a UNIX file system. UNIX uses LF as TERMSTR.&lt;/P&gt;
&lt;P&gt;Since you create this code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ...;
infile ...;
input ...;
output;
infile ...;
input ...;
output;
/* and so on */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;any input trying to read past the end of any one file will terminate the step, even if the other files still have data.&lt;/P&gt;
&lt;P&gt;To read multiple external files in a single DATA step, you must use only one INFILE statement which opens all the files in succession, either by supplying a list of names and using the FILEVAR= option, or by using wildcards.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 07:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890037#M351664</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-19T07:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do i read Multiple log files from a path having incremental version number to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890067#M351680</link>
      <description>&lt;P&gt;The macro is not generating the right code.&lt;/P&gt;
&lt;P&gt;But you don't need macro logic to read 17 different files in a data step.&amp;nbsp; Just data step logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pathname=some direcotry/;
%let file=some prefix;
%let ver=17;


data chk_lst;
  length ver 8 fname $50 filename $256 lineno 8 line $900;
  do ver=1 to &amp;amp;ver ;
    fname=cats("&amp;amp;file",ver);
    filename=cats("&amp;amp;pathname",fname);
    infile logfile filevar=filename end=eof truncover;
    do lineno=1 by 1 while (not eof);
      input line $char900.;
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2023 20:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-read-Multiple-log-files-from-a-path-having-incremental/m-p/890067#M351680</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-19T20:01:59Z</dc:date>
    </item>
  </channel>
</rss>

