SAS在数据步骤中为每个实例执行一个宏 [英] sas execute a macro for each instance in a data step
问题描述
我有一个宏,它可以在一组给定的时间范围内将数据插入表中.
I have a macro which inserts data into a table over a set of given time-frame.
它将遍历一系列从起始日期(存储在数据集中的日期),并使用proc sql insert语句运行宏.
It loops through a series of from-to dates (which are stored in a dataset) and runs the macro with a proc sql insert statement.
在所有这些操作的最后检查数据时,我注意到新数据集中只有最后的起始至结束期间的数据.
When checking the data at the end of all of this, I notice that only data from the final from-to period is in the new data set.
在数据步骤中调用宏时,这是我的代码.
Here is my code when calling the macro in the data step.
data _null_;
set extract_insert_dates;
%insert_table_extract(put(extract_start, date11.),put(extract_end, date11.));
run;
在数据步骤中,我还有什么要调用的功能,以便在每个起始时间段(而不是最后一个时间段)内插入数据(运行宏)吗?
Is there something else I should be calling in the data step for this to work and insert data (run the macro) for each of the from-to periods, as opposed to just the final one?
推荐答案
假设您是宏编译器,并将宏调用替换为它将生成的实际SAS代码.请记住,对于宏处理,put(extract_start, date11.)
和put(extract_end, date11.)
的参数值只是字符串.
Pretend you are the macro compiler and replace the macro call with the actual SAS code it will generate. Remember that to the macro process the parameter values of put(extract_start, date11.)
and put(extract_end, date11.)
are just strings of characters.
我怀疑您需要使用调用执行,以便可以将数据集变量extract_start
和extract_end
的值传递给宏.
I suspect that you need to use call execute so the values of the data set variables extract_start
and extract_end
can be passed to the macro.
data _null_;
set extract_insert_dates;
call execute(cats('%nrstr(%insert_table_extract)(',put(extract_start, date11.),',',put(extract_end,date11.),')'));
run;
这篇关于SAS在数据步骤中为每个实例执行一个宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!