Importing a Log file with file name

Reply
Frequent Contributor
Posts: 87

Importing a Log file with file name


I am importing a log file .log to handle error from log i am using the followoing code

data _null_;
                LENGTH DATE $ 18.;
                DATE2 ="&sysdate"D  ;
                DATE4="&systime"t;
                DATE3=PUT(DATE2,yymmddp10.);
                Date5=Put(DATE4,time8.)    ;
                vardttm =tranwrd(DATE3,':','.')||'_'||tranwrd(DATE5,':','.');
                call symput("DATETIME",COMPRESS(VARDTTM));
                run;
             %put &datetime;

i am gettig datetime=2013.04.17_10.36.00


    %put &systime;

filename mylog "path/Regreturns_Quarterly_Regreturns_Quarterly_&datetime..log"; 
filename report "path/Error_log_&datetime..txt";  

data _null_;
infile mylog;
input;
lineno+1;     /* Increment Line Number */
file report;
rec = _infile_;

/* Check for ERROR: type error message */
foundit = index(rec,"ERROR:");                                                                                     
if ( foundit > 0 ) then do;
put lineno " " rec;
end;

run;

my logs are saving with following names  "Regreturns_Quarterly_Regreturns_Quarterly_2013.04.17_10.15.15.log.15.log"

i want logs genetated between time 10:00 to 10:30 i want to ie minutes seconds must be neglected only hour must be considered so that i can get log

how can i import logs with file name "Regreturns_Quarterly_Regreturns_Quarterly_2013.04.17_10      .log"

Super Contributor
Posts: 644

Re: Importing a Log file with file name

Have you tried  "Regreturns_Quarterly_Regreturns_Quarterly_2013.04.17_10*.log"

Richard

Frequent Contributor
Posts: 87

Re: Importing a Log file with file name

Posted in reply to RichardinOz

"Regreturns_Quarterly_Regreturns_Quarterly_2013.04.17_10*.log"

if i have 2 logs 10.15 one and 10.45

which one will it take i want to take latest ie 10.45 how i can take greater time

Super Contributor
Posts: 644

Re: Importing a Log file with file name

Assuming you can write the code to create the date and hour parts of the filename string

%let logfile = Regreturns_Quarterly_Regreturns_Quarterly_&datestr._ ;

Data _null_ ;

     Do  min  =   59 to 0 by -1 ;

          minstr = put (min, z2) ;

          searchfile = "&logfile.&hrstr.."||minstr||".log" ;

          If filexist(searchfile) then min =  -99

     end ;

     if min = -99 then

          do ;

               call symput ("searchfile",  searchfile) ;

               return

          end ;

     * If not found, search previous hour ;

     Do  min  =   59 to 0 by -1 ;

          minstr = put (min, z2) ;

          searchfile = "&logfile.%eval(&hrstr - 1)."||minstr||".log" ;

          If filexist(searchfile) then min =  -99

     end ;

     call symput ("searchfile",  searchfile) ;

Run ;

NB - untested code

Richard

Respected Advisor
Posts: 3,799

Re: Importing a Log file with file name

santhosh wrote:


I am importing a log file .log to handle error from log i am using the followoing code



/* Check for ERROR: type error message */
foundit = index(rec,"ERROR:");                                                                                    
if ( foundit > 0 ) then do;
put lineno " " rec;
end;

run;

You're going to need to fix that.  I debug programs all the time for programmers that use log checkers that don't work.

17         data _null_;
18            =;
              _
             
180
ERROR
180-322: Statement is not valid or it is used out of proper order.

19            run;
Ask a Question
Discussion stats
  • 4 replies
  • 202 views
  • 0 likes
  • 3 in conversation