简体   繁体   English

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. 我有一个宏,可以在给定的时间范围内将数据插入表中。

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. 它遍历一系列从头到尾的日期(存储在数据集中),并使用proc sql insert语句运行宏。

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? 我还需要在数据步骤中调用其他方法,以使其工作并为每个起始时间段而不是最后一个周期插入数据(运行宏)吗?

Pretend you are the macro compiler and replace the macro call with the actual SAS code it will generate. 假设您是宏编译器,然后将宏调用替换为它将生成的实际SAS代码。 Remember that to the macro process the parameter values of put(extract_start, date11.) and put(extract_end, date11.) are just strings of characters. 请记住,在宏处理中, put(extract_start, date11.)put(extract_end, date11.)的参数值只是字符串。

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. 我怀疑您需要使用调用执行,以便可以将数据集变量extract_startextract_end值传递给宏。

data _null_;
  set extract_insert_dates;
  call execute(cats('%nrstr(%insert_table_extract)(',put(extract_start, date11.),',',put(extract_end,date11.),')'));
run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM