BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Melvin_Sas
Fluorite | Level 6

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
%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.

--
Paige Miller

View solution in original post

4 REPLIES 4
collinelliot
Barite | Level 11

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

Melvin_Sas
Fluorite | Level 6

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.

 

PaigeMiller
Diamond | Level 26
%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.

--
Paige Miller
Melvin_Sas
Fluorite | Level 6

Ok thanks.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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