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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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