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 !
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" ;' );
Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic.
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" ;' );
Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic.
it works perfectly!
Thanks a lot!
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.