Hi:
Before Scott saves your life, you might be able to save your own life by reading this introduction to macro processing.
http://www2.sas.com/proceedings/sugi28/056-28.pdf
As a general rule, you cannot have a PROC step -inside- a DATA step program. The beginning of the PROC step will act as a step boundary to the DATA step program. However, if you learn a bit more about macro processing and the use of %IF in order to conditionally compile and execute program code, there is a design for your macro program that does not involve submitting a PROC GCHART from within a DATA step.
Consider, this possible design for a macro program and sample program execution:
[pre]
%macro dorept(parm1=, parm2=);
data mysubset;
** logic to build your subset probably using &PARM1 and &PARM2;
run;
** logic to get number of obs into macro variable;
proc sql noprint;
select nobs into :nobs
from dictionary.tables
where libname = 'WORK' and
memname = 'MYSUBSET';
quit;
%let nobs=&nobs;
%put number of obs in work.mysubset is: &nobs;
%if &nobs eq 0 %then %do;
** issue Message for 0 obs;
title "Error Message";
data _null_;
length Message $75;
file print ods;
Message = "<div><h3>Message of some sort</h3></div>";
put _ods_;
Message = "<div><h3>Please correct input and try again</h3></div>";
put _ods_;
run;
%end;
%else %if &nobs gt 0 %then %do;
** if number of obs gt 0 then send 2 Proc Gcharts to be executed;
proc gchart data=work.mysubset;
** GCHART statements for obs gt 0;
run;
quit;
proc gchart data=work.mysubset;
** More GCHART statements for obs gt 0;
run;
quit;
%end;
%mend dorept;
** test the macro program with parameters that result in 0 obs;
ods html path='.'(url=none) file="try1.html" style=sasweb;
** &PARM1 and &PARM2 values result in OBS=0 for work.mysubset;
%dorept(parm1=xxx, parm2=yyy);
ods html close;
title;
** test the macro program with parameters that result in OBS gt 0;
ods html path='.'(url=none) file="try2.html" style=sasweb;
** &PARM1 and &PARM2 values will result in OBS gt 0;
%dorept(parm1=aaa, parm2=bbb);
ods html close;
title;
[/pre]
Note how the ODS HTML statements surround the invocation of the %DOREPT macro program. Note also that the %DOREPT macro program is composed of discrete steps:
--1) create WORK.MYSUBSET -- probably using some macro parameters that you pass into the macro program when you invoke it
--2) get the number of OBS into a macro variable by using DICTIONARY.TABLES (there are other methods for retrieving the number of OBS and you could use any of them here).
--3) test the &NOBS macro variable -- if &NOBS = 0 then use a DATA _NULL_ step to write an error message to the open destination.
--4) on the %ELSE condition, when &NOBS gt 0 then put your 2 PROC GCHART or your other graph steps here
--5) end the macro program definition
--6) test the macro program by invoking 1 time with parameters that will generate 0 obs (to see the error message in the HTML file)
--7) test the macro program by invoking a second time with parameters that will generate obs in the subset for the graph programs.
This is just one possible design. Since it's not entirely clear what your processing need is, it's hard to come up with a very detailed macro program example -- so this is just a "shell" program. Of course, once you read the introduction to macro processing (which also has some conditional macro logic examples), you may have some other ideas.
Although you could invoke a macro program with CALL EXECUTE from within a DATA step program, the program code generated with CALL EXECUTE is placed into a buffer stack and would only be executed after the DATA step program was over. You may not need to perform this more advanced type of macro processing if the above approach will work for your scenario.
The SAS Macro Facility is acting like a big typewriter. You do not need to have your %IF statement in a DATA step program in order to conditionally generate code, however, your %IF statements MUST be enclosed in a Macro program definition, (as explained in the recommended paper) -- you cannot use %IF in open code. However, once used properly in a SAS Macro program, your %IF/%ELSE statements can be used to generate single statements within a program, parts of statements, whole steps or entire multi-step programs.
cynthia