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.
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.