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);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.