In macro I am trying to read a string from a file and then send email if it exists.I am using the below code for that and getting few errors.Can someone help me to fix the errors.
%macro FileProcess;
Infile 'C:\Users\FSAX.txt' truncover;
input a_line $200.;
%if index(a_line, 'ERROR:') > 0 %then %do;
%Let Message = "Hello";
%Email();
%end;
%Mend;
%FileProcess;
NOTE: Line generated by the invoked macro "FILEPROCESS".
1 Infile 'C:\Users\FSAX.txt' truncover;
------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: Line generated by the invoked macro "FILEPROCESS".
1 input a_line $200.;
-----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
ERROR: Required operator not found in expression: index(a_line, 'ERROR:') > 0
ERROR: The macro FILEPROCESS will stop executing.
%if index(a_line, 'ERROR:') > 0 %then %do;
%Let Message = "Hello";
These two statements should not be macro statements, and will not work as macro statements. You need
if index(a_line, 'ERROR:') > 0 then do; message = 'Hello'; end;
As stated by the other respondent, you also need a DATA statement for any of this to work.
You don't have a data statement before the infile. Might be other issues, but that's critical.
Thanks.. added the datastep but still getting the below error
2939 %global Message;
2940 %macro FileProcess;
2941 data _null_;
2942 Infile 'C:\Users\FSAX.txt' truncover;
2943 input a_line $2000.;
2944 %if index(a_line, 'ERROR:') > 0 %then %do;
2945 %Let Message = "Hello";
2946 %Email();
2947 %end;
2948
2949 %Mend;
2950
2951 %FileProcess;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 12.67 seconds
cpu time 1.24 seconds
ERROR: Required operator not found in expression: index(a_line, 'ERROR:') > 0
ERROR: The macro FILEPROCESS will stop executing.
%if index(a_line, 'ERROR:') > 0 %then %do;
%Let Message = "Hello";
These two statements should not be macro statements, and will not work as macro statements. You need
if index(a_line, 'ERROR:') > 0 then do; message = 'Hello'; end;
As stated by the other respondent, you also need a DATA statement for any of this to work.
Ok thanks.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.