Hello,
I was asked to delete out a portion of the below code and when I do I am getting an error that states ERROR 160-185: No matching IF-THEN clause. Any ideas on what I am missing?
(This was the original code: - ran no problem)
data test;
set aa.test;
if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9)=0 then
do;
if O3 in ('G2','O3') and &month < 201901 then
do;
%inc "./test.inc";
end;
else
do;
%inc "./test.inc";
end;
end;
run;
(Code where I deleted what was requested and now getting above error)
data test;
set aa.test;
if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9)=0 then
do;
else
do;
%inc "./test.inc";
end;
end;
run;
@girlieq97 wrote:
thanks for your response. I am not sure I follow, but the jist is the way it is written I can't just remove the requested part and run as is. I need to change a couple of things due to the include file. Trying now thank you.
Your first do has nothing in the ‘do’ section and the ‘end’ needs to come before the ‘else’. You have two do and two end, but not in the right places. See the DO in red. Where is the matching end?
@girlieq97 wrote:
Hello,
I was asked to delete out a portion of the below code and when I do I am getting an error that states ERROR 160-185: No matching IF-THEN clause. Any ideas on what I am missing?
(This was the original code: - ran no problem)
data test;
set aa.test;if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9)=0 then
do;
if O3 in ('G2','O3') and &month < 201901 then
do;
%inc "./test.inc";
end;
else
do;
%inc "./test.inc";
end;
end;
run;
(Code where I deleted what was requested and now getting above error)
data test;
set aa.test;if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9)=0 then
do;
else
do;%inc "./test.inc";
end;
end;
run;
Actually %INC has a few things I missed. One it’s a global statement so cannot be used with conditional logic. Second is it has to follow a semicolon.
Try switching If/Then to %if/%then/%do. If you’re using an older version of SAS you’ll have to wrap the program in a macro.
Heres the reference for this.
@girlieq97 wrote:
thanks for your response. I am not sure I follow, but the jist is the way it is written I can't just remove the requested part and run as is. I need to change a couple of things due to the include file. Trying now thank you.
Start with proper code formatting that lines up the do's with the end's:
data test;
set aa.test;
if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9) = 0
then do;
if O3 in ('G2','O3') and &month < 201901
then do;
%inc "./test.inc";
end;
else do;
%inc "./test.inc";
end;
end;
run;
This code immediately rings my alarm bells; as both branches of the inner if execute the same code, that inner if is useless and should be removed anyway.
Now, if all you need to do is to do nothing if the inner if is true, you just remove one line:
data test;
set aa.test;
if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9) = 0
then do;
if O3 in ('G2','O3') and &month < 201901
then do;
end;
else do;
%inc "./test.inc";
end;
end;
run;
and the code structure remains intact.
Writing code in a properly structured manner is one of the foundations for efficient programming, see Maxim 12.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.