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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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