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

 

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

Rules for Using %INCLUDE

 
  • You can specify any number of sources in a %INCLUDE statement, and you can mix the types of included sources. However, although it is possible to include information from multiple sources in one %INCLUDE statement, it might be easier to understand a program that uses separately coded %INCLUDE statements for each source.
  • The %INCLUDE statement must begin at a statement boundary. That is, it must be the first statement in a SAS job or must immediately follow a semicolon that ends another statement. A %INCLUDE statement cannot immediately follow a DATALINES, DATALINES4, CARDS, or CARDS4 statement (or PARMCARDS or PARMCARDS4 statement in procedures that use those statements). However, you can include data lines with the %INCLUDE statement using one of these methods:
    • Make the DATALINES, DATALINES4 statement or the CARDS, CARDS4 statement the first line in the file that contains the data.
    • Place the DATALINES, DATALINES4 statement or the CARDS, CARDS4 statement in one file, and the data lines in another file. Use both sources in a single %INCLUDE statement.
    The %INCLUDE statement can be nested within a file that has been accessed with %INCLUDE. The maximum number of nested %INCLUDE statements that you can use depends on system-specific limitations of your operating environment (such as available memory or the number of files that you can have open concurrently).
  • Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic.

View solution in original post

10 REPLIES 10
Reeza
Super User

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;


 

Reeza
Super User
You could just change the condition to be:

if sum(....) ne 0 the do %inc ‘./test.inc’;
girlieq97
Obsidian | Level 7
like this?

data test;
set aa.test;
if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9)=0 then
do %inc "./test.inc";
run;
Reeza
Super User
You need to flip the condition. See mine, yours is different.
Reeza
Super User

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. 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lestmtsglobal&docsetTarge...

girlieq97
Obsidian | Level 7
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.
Reeza
Super User
Is your example code, your actual code? That would never have worked correctly is one problem.
Reeza
Super User

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

 

Rules for Using %INCLUDE

 
  • You can specify any number of sources in a %INCLUDE statement, and you can mix the types of included sources. However, although it is possible to include information from multiple sources in one %INCLUDE statement, it might be easier to understand a program that uses separately coded %INCLUDE statements for each source.
  • The %INCLUDE statement must begin at a statement boundary. That is, it must be the first statement in a SAS job or must immediately follow a semicolon that ends another statement. A %INCLUDE statement cannot immediately follow a DATALINES, DATALINES4, CARDS, or CARDS4 statement (or PARMCARDS or PARMCARDS4 statement in procedures that use those statements). However, you can include data lines with the %INCLUDE statement using one of these methods:
    • Make the DATALINES, DATALINES4 statement or the CARDS, CARDS4 statement the first line in the file that contains the data.
    • Place the DATALINES, DATALINES4 statement or the CARDS, CARDS4 statement in one file, and the data lines in another file. Use both sources in a single %INCLUDE statement.
    The %INCLUDE statement can be nested within a file that has been accessed with %INCLUDE. The maximum number of nested %INCLUDE statements that you can use depends on system-specific limitations of your operating environment (such as available memory or the number of files that you can have open concurrently).
  • Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic.
girlieq97
Obsidian | Level 7
thank you I was able to correct the code to below.

set aa.test;
if sum(e1,e2,e3,e4a,e4b,e5,e6,e7,e8,e9)=0 then
do;
%inc "./test.inc";
end;
run;
Kurt_Bremser
Super User

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.

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
  • 10 replies
  • 990 views
  • 4 likes
  • 3 in conversation