New here, so if I did something wrong, I apologize. I'm new user of SAS as well.
I created a macro that calls first a proc sql that creates a certain table that I want to pass it to another macro (inside the first macro).
%Macro Mc_Copy_Table (TABLE_NAME);
proc sql;
create table &TABLE_NAME as
select *
from OR_IN.&TABLE_NAME;
connect using OR_OUT;
execute (truncate table &TABLE_NAME) By OR_OUT;
disconnect from OR_OUT;
quit;
%MC_obsnvars(&TABLE_NAME);
%put &Nobs;
%if &Nobs > 100000 %then
%do; /* use of the sql loader */
proc append base = OR_OU. &TABLE_NAME (&BULKLOAD_OPTION)
data = &TABLE_NAME;
run;
%end;
%else
%do;
proc append base = OR_OU. &TABLE_NAME (Insertbuff=10000)
data = &TABLE_NAME;
run;
%end;
%Mend Mc_Copy_Table;
The Mc_Obsnvars macro use the attrn
function to get the number of observations from the given dataset (it opens the dataset first). Depending on the number of observations, my program either use the sqlloader or not. OR_IN and OR_OUT are libnames (oracle engine).
When The macro Mc_Copy_Table is executed, with let's say TABLE1 as argument, the Mc_Obsnvars is executed first which tries to open TABLE1 which doesn't exist yet. The proc sql is executed afterwards.
Why the macro is executed before the proc sql
? and is there any way to have the proc sql
be executed first ? putting the proc sql
part in a macro doesn't solve the problem. Thanks :)
create table
statement before your macro call? If not, then the %Mc_Obsnvars() will be executed before thecreate table
is executed. Where does your PROC SQL step end? Also, is %Mc_Obsnavars() generating any SAS code, or is it just populating a macro variable? – Quentin