data test;
if compress(&MON1.)= compress(&MON2.)
then I want to run this program "C:\Nitin(C)\SAS & SQL\SAS\SAS_Excel_VBA_Program.sas";
else Put 'NA';
RUN;
/*I tried call execute and %include but both options not working*/
Any help will be highly appreciated. thanks!
Assuming your external program is not only a code snippet for inclusion into a data step but a full program, here some options how to do this. The sample code below is self-contained and fully functional.
/* create sample demo program demo.sas in SAS Work folder */
%let work_path=%sysfunc(pathname(work));
data _null_;
file "&work_path/demo.sas";
put 'proc print data=sashelp.class(obs=1);run;';
run;
%let mon1=Feb2020;
%let mon2=Feb2020;
/* option 1 */
data _null_;
if compress("&MON1.")= compress("&MON2.") then
do;
call execute('%include '||"'&work_path/demo.sas' /source2;");
end;
else Put 'NA';
stop;
RUN;
/* option 2 */
%macro doit(m1,m2);
%if &m1=&m2 %then
%do;
%include "&work_path/demo.sas" /source2;
%end;
%else
%put NA;
%mend;
%doit(&mon1,&mon2);
/* option 3 (requires a recent SAS release) */
%if &mon1=&mon2 %then
%do;
%include "&work_path/demo.sas" /source2;
%end;
%else
%do;
%put NA;
%end;
Assuming your external program is not only a code snippet for inclusion into a data step but a full program, here some options how to do this. The sample code below is self-contained and fully functional.
/* create sample demo program demo.sas in SAS Work folder */
%let work_path=%sysfunc(pathname(work));
data _null_;
file "&work_path/demo.sas";
put 'proc print data=sashelp.class(obs=1);run;';
run;
%let mon1=Feb2020;
%let mon2=Feb2020;
/* option 1 */
data _null_;
if compress("&MON1.")= compress("&MON2.") then
do;
call execute('%include '||"'&work_path/demo.sas' /source2;");
end;
else Put 'NA';
stop;
RUN;
/* option 2 */
%macro doit(m1,m2);
%if &m1=&m2 %then
%do;
%include "&work_path/demo.sas" /source2;
%end;
%else
%put NA;
%mend;
%doit(&mon1,&mon2);
/* option 3 (requires a recent SAS release) */
%if &mon1=&mon2 %then
%do;
%include "&work_path/demo.sas" /source2;
%end;
%else
%do;
%put NA;
%end;
Hi Patrick,
A quick query - why we are using / source2?
Thanks,
Nitin
The source2 option prints the code from an %include statement to the log. That shows you what got executed and also supports debugging if required.
Btw: You probably should mark my answer as solution and not your "thank you". Except for rare cases it's bad style to mark your own stuff as solution.
Thanks Patrick!
I marked your answer as solution.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.