I'm trying to read the series of files from .txt file via SAS macros. However I could not succeed for unknown reason. I'm puzzled where to resolve this error. Could someone check that my infile statement is do loops are having any issue?
Your help is greatly appreciated
My code looks like,
data log.output_file ;
infile "&path/output_file.txt" firstobs=2 truncover ;
input fname $400. ;
run;
%macro log_analysis;
%let filedate=%sysfunc(putn("&sysdate9"d-1,yymmdd10.));
%put &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' 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 var var1;
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;
First datastep to create a dataset log.output_file was succeed and it has 3 observations as follows.
fname
/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-25_tmptcmsaslva2_19142.log
/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-25_tmptcmsaslva2_18208.log
When I run my code I got error as follows,
NOTE: CALL EXECUTE generated line.
1 + 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.; var1 = _infile_; if var1 = :'201' then
do;
2 + 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 var var1; run;
NOTE: The variable fname 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 DUMMY is:
Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-25_tmptcmsaslva2_19142.log,
Owner Name=sassrv,Group Name=sas,
Access Permission=rwxrwxr-x,
Last Modified=Sat Sep 26 00:00:33 2015,
File Size (bytes)=8555812
NOTE: The infile DUMMY is:
Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-25_tmptcmsaslva2_18208.log,
Owner Name=sassrv,Group Name=sas,
Access Permission=rwxrwxr-x,
Last Modified=Sat Sep 26 02:10:34 2015,
File Size (bytes)=1831
ERROR: Invalid physical name.
fname= filename= end_of_file=1 var= var1= Date_TimeStamp= Status= Processid= userid= Details= _ERROR_=1 _INFILE_= _N_=3
NOTE: The SAS System stopped processing this step because of errors.
NOTE: SAS set option OBS=0 and will continue to check statements. This might cause NOTE: No observations in data set.
NOTE: There were 3 observations read from the data set LOG.OUTPUT_FILE.
WARNING: The data set LOG.LOG_ANALYSIS may be incomplete. When this step was stopped there were 67962 observations and 6 variables.
The 3rd observation in log.output_file is empty (fname='') ?
Try:
data log.output_file ;
infile "&path/output_file.txt" firstobs=2 truncover lrecl=400;
input fname $400.;
if fname ne '';
run;
When I recreate the .txt file, error did not appears.
There you go!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.