Hi,
I'm new to SAS Programming (9.3) and I'm struggling with setting a variable filename for the INFILE-statement.
Goal :
I want to treat a list of SAS logfiles. The full path name of the file is retrieved from a newly created dataset (SASLOGS. LOGFILES). This dataset was created by a 'ls' on a UNIX-directory where SAS logs are stored (see step 1 in code snippet).
Problem:
In the INFILE-statement, I don't succeed in retrieving the correct value of the file -> ERROR: Invalid physical name.
Eventhough, the variable 'saslogfile_fullpath' contains the correct path (with ""). See code snippet.
Code snippet :
/*1. Fill SASLOGS.LOGFILES with all filenames listed in directory*/
filename dirlist pipe "ls /sas/prd/common/SASApp_IAM_WorkspaceServer_*.log";
LIBNAME SASLOGS "/sas/prd/data/IAM/SASLOGS";
data SASLOGS.LOGFILES;
infile dirlist lrecl=200 truncover;
input file_name $200.;
run;
/* 2. Use SASLOGS.LOGFILES and handle each file (see value "file_name") seperately*/
LIBNAME SASLOGS "/sas/prd/data/IAM/SASLOGS";
%let saslogfile_fullpath=' ';
data work.ONE_LOGFILE;
set SASLOGS.LOGFILES;
saslogfile_fullpath=trim(file_name);
saslogfile_fullpath='"' || strip(saslogfile_fullpath) || '"';
putlog saslogfile_fullpath;/* correct value in saslogfile_fullpath*/
infile &saslogfile_fullpath firstobs=2 length=linelength;
input @1 date YYMMDD10.
+1 time TIME8.
@24 level $5. @;
lengthSASInfo=linelength-52;
input @53 SAS_info $VARYING500. lengthSASInfo;
/* call macro to treat logfile*/
RUN;
What I'm I doing wrong?
Thanks for your assistance.
Jurgen
When you do this:
infile &saslogfile_fullpath firstobs=2 length=linelength;
you reference a macro variable; this reference is resolved once while the datastep is compiled, and requires the macro variable to be present at that time.
A code snippet that reads all lines from a bunch of textfiles into a dataset would look like this:
filename dirlist pipe "ls /sas/prd/common/SASApp_IAM_WorkspaceServer_*.log";
data dirlist;
infile dirlist truncover;
input logfile $200.;
run;
data logtext;
set dirlist;
infilename = logfile;
infile xxx filevar=infilename end=eof truncover;
do until (eof);
input textline $200.;
output;
end;
run;
Please share your log, thanks.
Your first data step based in your code (which i did too) is working fine. I am not sure about the 2nd data step. I don't know how different the contents of ls command in unix versus dir command in Windows.
When you do this:
infile &saslogfile_fullpath firstobs=2 length=linelength;
you reference a macro variable; this reference is resolved once while the datastep is compiled, and requires the macro variable to be present at that time.
A code snippet that reads all lines from a bunch of textfiles into a dataset would look like this:
filename dirlist pipe "ls /sas/prd/common/SASApp_IAM_WorkspaceServer_*.log";
data dirlist;
infile dirlist truncover;
input logfile $200.;
run;
data logtext;
set dirlist;
infilename = logfile;
infile xxx filevar=infilename end=eof truncover;
do until (eof);
input textline $200.;
output;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.