DATA Step, Macro, Functions and more

Infile and Macro

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Infile and Macro

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.

 


Accepted Solutions
Solution
‎04-13-2017 04:14 PM
Trusted Advisor
Posts: 1,615

Re: Infile and Macro

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

View solution in original post


All Replies
PROC Star
Posts: 288

Re: Infile and Macro

You don't have a data statement before the infile. Might be other issues, but that's critical.

Occasional Contributor
Posts: 10

Re: Infile and Macro

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.

 

Solution
‎04-13-2017 04:14 PM
Trusted Advisor
Posts: 1,615

Re: Infile and Macro

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

Occasional Contributor
Posts: 10

Re: Infile and Macro

Ok thanks.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 161 views
  • 0 likes
  • 3 in conversation