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

if  any value  contains "no"  then execute program_1.sas, else execute program_2.sas. the errors " error 180-322:statement is not valid or its is used out or proper order" and error " else  statement  is not valid or it is used out of proper order. the sample is attached.

Can someone help?

data _null_;

length comp_lst $20;

do until (eof);

set a (keep=verified ) end=eof;

comp_lst=catx(" ",comp_lst,verified);

end;

drop verified;

if index(comp_lst,"no")>0 then %include "\program_1.sas";

else if index(comp_lst, "no")<1 then %include "\program_2.sas";

run;

 

Thanks !

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I don't think %INCLUDE can be run conditionally. You need to use CALL EXECUTE() instead to call that program. 

 

Something like this maybe:

if index(comp_lst,"no")>0 then call execute('%include "\program_1.sas"; ');

else if index(comp_lst, "no")<1 then call execute('%include "\program_2.sas" ;' );

 

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

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

5 REPLIES 5
VENKATAMAHESH
Calcite | Level 5
use call execute functionality when a certain condition is satisfied. it would work.
GraceStehlin98
Calcite | Level 5
if you have better idea to check a value "no" from the variable "verified", that will be great too!. I don't know why "%include" doesn't work .

Thanks !
Reeza
Super User

I don't think %INCLUDE can be run conditionally. You need to use CALL EXECUTE() instead to call that program. 

 

Something like this maybe:

if index(comp_lst,"no")>0 then call execute('%include "\program_1.sas"; ');

else if index(comp_lst, "no")<1 then call execute('%include "\program_2.sas" ;' );

 

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

Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic.

Shmuel
Garnet | Level 18

 Alternative code using macro program:

data _NULL_;
   set a (keep=verified ) end=eof;
   comp_lst=catx(" ",comp_lst,verified);
   if eof then do;
      result = index(comp_lst,"no");
	  call symput('result', strip(result));
   end;
run;
%run_program(rc);
   %if &rc > 0 %then %include "\program_1.sas";
   %if &rc < 1 %then %include "\program_2.sas";
%mend run_program;
%run_program(&result);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1021 views
  • 1 like
  • 4 in conversation