I have tried the following code:
%macro check_file(infile);
%if %sysfunc(fileexist(&infile)) %then %do;
%let filrf = myfile;
%let rc = %sysfunc(filename(filrf, &infile));
%let infid = %sysfunc(fopen(&filrf, i));
%if &infid > 0 %then %do;
%do %while(%sysfunc(fread(&infid) = 0);
%let rc = sysfunc(fget(&infid, mystring, 32767));
%if %sysfunc(indexc(%superq(mystring), %^&)) > 0 %then %do;
%let mystring1 = %sysfunc(tranwrd(%superq(mystring), %, ~));
%let mystring1 = %sysfunc(tranwrd(superq(mystring1), &,^));
%put The contents of the file are %superq(mystring1);
%end;
%else %do;
%put The contents of the file are %superq(mystring);
%end;
%end;
%end;
%let rc = %sysfunc(fclose(&infid));
%end;
%else %do;
%put Could not open the file &infile;
return;
%end;
%end;
%else %do;
%put The file &infile does not exist;
%end;
%mend check_file;
Here, I have tried to replace % with ~ and & with ^ as these characters when found in the input file are getting evaluated and giving errors. But, if lines containing % and ^ characters could be written as it is to the output file then it will be very helpful. Also, I have not tried yet the code for writing to the output file, instead I am writing to the log. But, need to write to the output file.
With the above code, I was getting some warnings like when the line is %macro namex(name=, number=); WARNING: Apparent symbolic reference NUMBER not resolved.
When the line is like this: %do n= 1 %to &number; then WARNING: Apparent symbolic reference NAME not resolved. WARNING: Apparent symbolic reference N not resolved.
... View more