sas 为数据步骤中的每个实例执行一个宏 [英] sas execute a macro for each instance in a data step

查看:21
本文介绍了sas 为数据步骤中的每个实例执行一个宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宏,它可以在一组给定的时间范围内将数据插入表中.

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_startextract_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆