Tengo 2 macros debajo que estoy tratando de ejecutar 1 tras otro como un ciclo utilizando una tabla de metadatos y el comando ejecutar llamada en un paso de datos.Problema de variables macro al usar ejecutar llamada
macro% TWO requiere la variable global & names_agg. se supone que debe ser creado en macro% ONE. Sin embargo, en el código siguiente, & names_agg está en blanco la primera vez que lo ejecuto. Si lo ejecuto nuevamente, solo mantendrá el valor de la última vez que se ejecutó.
La idea es que cada vez que se ejecute% ONE, un nuevo & names_agg. es creado.
¿Qué estoy haciendo mal?
Gracias
%macro ONE(condition);
%global names_agg;
%let names_agg = ;
proc sql;
select
cats(name,"_agg"),
into
:names_agg separated by " ",
from dataset
where condition = "&condition."
;
quit;
%mend;
%macro TWO(name_OT);
data &name_OT.;
set &names_agg.;
run;
%mend;
data _null_;
length code $32767;
set meta_table;
code = "%ONE(" || cats(condition) || "); %TWO(" || cats(Name_OT) || ");";
call execute(code);
run;
Lo siento por el registro desordenado, este es el código real. El problema es con NAMES_AGG_A -B y _C sin resolviendo correctamente
871 data test;
872 length code $32767;
873 set c.new_name_OT (obs=1);
874 code = '%OT_Append(' || cats(portfolio) || ',' || cats(scorecard) || ',' ||
874! cats(event_table) || ',' ||
875 cats(scorecard_type) || ',' || cats(obs_period) || ',' || cats(outcome_period) ||
875! ',' || cats(x_var) ||
876 ',' || cats(y_var) || ',' || cats(use) || ',' || cats(condition) || '); %put
876! &names_agg_a.; %OT_Append2(' || cats(Name_OT) || ');';
877 call execute(code);
878 run;
MLOGIC(OT_APPEND): Beginning execution.
MLOGIC(OT_APPEND): Parameter PORTFOLIO has value MTG
MLOGIC(OT_APPEND): Parameter SCORECARD has value A
MLOGIC(OT_APPEND): Parameter EVENT_TABLE has value event_table_name
MLOGIC(OT_APPEND): Parameter SCORECARD_TYPE has value Application
MLOGIC(OT_APPEND): Parameter OBS_PERIOD has value 1
MLOGIC(OT_APPEND): Parameter OUTCOME_PERIOD has value 18
MLOGIC(OT_APPEND): Parameter X_VAR has value PI
MLOGIC(OT_APPEND): Parameter Y_VAR has value GB_Odds
MLOGIC(OT_APPEND): Parameter USE has value Development
MLOGIC(OT_APPEND): Parameter CONDITION has value
MLOGIC(OT_APPEND): %LET (variable name is NAMES_AGG_A)
MLOGIC(OT_APPEND): %LET (variable name is NAMES_AGG_B)
MLOGIC(OT_APPEND): %LET (variable name is NAMES_AGG_C)
MPRINT(OT_APPEND): proc sql;
SYMBOLGEN: Macro variable PORTFOLIO resolves to MTG
SYMBOLGEN: Macro variable SCORECARD resolves to A
SYMBOLGEN: Macro variable EVENT_TABLE resolves to event_table_name
SYMBOLGEN: Macro variable SCORECARD_TYPE resolves to Application
SYMBOLGEN: Macro variable OBS_PERIOD resolves to 1
SYMBOLGEN: Macro variable OUTCOME_PERIOD resolves to 18
SYMBOLGEN: Macro variable X_VAR resolves to PI
SYMBOLGEN: Macro variable Y_VAR resolves to GB_Odds
SYMBOLGEN: Macro variable USE resolves to Development
SYMBOLGEN: Macro variable CONDITION resolves to
MPRINT(OT_APPEND): select cats("c.",name,"_agg_a"), cats("c.",name,"_agg_b"),
cats("c.",name,"_agg_c") into :names_agg_a separated by " ", :names_agg_b separated by " ",
:names_agg_c separated by " " from c.datasets_pit where portfolio = "MTG" and scorecard = "A"
and event_table = "event_table_name" and scorecard_type = "Application" and obs_period = 1 and
outcome_period = 18 and x_var = "PI" and y_var = "GB_Odds" and use = "Development" and
condition = "" ;
MPRINT(OT_APPEND): quit;
MLOGIC(OT_APPEND): Ending execution.
SYMBOLGEN: Macro variable NAMES_AGG_A resolves to
En esencia, el problema es que aquí, la declaración pone por encima de la llamada ejecutar programas que NAMES_AGG_A resuelve nada.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
MLOGIC(OT_APPEND2): Beginning execution.
MLOGIC(OT_APPEND2): Parameter NAME_OT2 has value MTG_Dev_OT_1
SYMBOLGEN: Macro variable NAME_OT2 resolves to MTG_Dev_OT_1
MPRINT(OT_APPEND2): data c.MTG_Dev_OT_1_ODDS;
SYMBOLGEN: Macro variable NAMES_AGG_A resolves to
MPRINT(OT_APPEND2): set ;
MPRINT(OT_APPEND2): run;
SYMBOLGEN: Macro variable NAME_OT2 resolves to MTG_Dev_OT_1
MPRINT(OT_APPEND2): data c.MTG_Dev_OT_1_GINI;
SYMBOLGEN: Macro variable NAMES_AGG_B resolves to
MPRINT(OT_APPEND2): set ;
MPRINT(OT_APPEND2): run;
SYMBOLGEN: Macro variable NAME_OT2 resolves to MTG_Dev_OT_1
MPRINT(OT_APPEND2): data c.MTG_Dev_OT_1_DIST;
SYMBOLGEN: Macro variable NAMES_AGG_C resolves to
MPRINT(OT_APPEND2): set ;
MPRINT(OT_APPEND2): run;
MLOGIC(OT_APPEND2): Ending execution.
NOTE: There were 1 observations read from the data set C.NEW_NAME_OT.
NOTE: The data set WORK.TEST has 1 observations and 12 variables.
NOTE: CALL EXECUTE generated line.
1 + proc sql;
1 + select cats("c.",name,"_agg_a"),
cats("c.",name,"_agg_b"), cats("c.",name,"_agg_c") into
:names_agg_a separated by " ", :names_agg_b separated by " ",
2 + :names_agg_c separated by " " from c.datasets_pit where portfolio =
"MTG" and scorecard = "A" and event_table = "event_table_name"
and scorecard_type = "Application" and
3 + obs_period = 1 and outcome_period = 18 and x_var = "PI"
and y_var = "GB_Odds" and use = "Development" and
condition = "" ; quit;; data c.MTG_Dev_OT_1_ODDS; set
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
4 + ; run;
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set C.MTG_DEV_OT_1_ODDS has 1 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
4 + data c.MTG_Dev_OT_1_GINI; set ; run;
NOTE: There were 1 observations read from the data set C.MTG_DEV_OT_1_ODDS.
NOTE: The data set C.MTG_DEV_OT_1_GINI has 1 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
4 + data c.MTG_Dev_OT_1_DIST; set ; run;
NOTE: There were 1 observations read from the data set C.MTG_DEV_OT_1_GINI.
NOTE: The data set C.MTG_DEV_OT_1_DIST has 1 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Gracias Chang! Acabo de agregar% nrstr a mi código y ¡ha resuelto mi problema! – MarkG