简体   繁体   English

将SAS数据集列作为宏参数传递

[英]Passing SAS dataset column as macro parameter

I have a SAS dataset with values 我有一个带有值的SAS数据集

yyyymm
201605
201606
201607
201608
201609

I am trying to find a way to pass these values one at a time to macro such that 我试图找到一种方法一次将这些值传递给宏,这样

do while dataset still has value
%macro passdata(yyyymm);
end

How can I do this in SAS. 如何在SAS中执行此操作。 Can someone please help with a sample/code snippet. 有人可以帮忙提供示例代码段吗?

As mentioned by the prior comment, a way to pass parameters is through call execute routine. 如先前的评论所述,传递参数的方法是通过调用执行例程。 Note that this must be done in datastep environment. 请注意,这必须在datastep环境中完成。 The lines are read from the set you input. 这些行是从您输入的集中读取的。

You can input multiple variables. 您可以输入多个变量。 Just add more variables in '||' 只需在“ ||”中添加更多变量 separators. 分隔符。 Note that the variables may have a lot of whitespaces in them. 请注意,变量中可能包含很多空格。 (==Do comparisons with care.) (==请谨慎进行比较。)

Here is a small sample code. 这是一个小的示例代码。 Tested. 测试。

data start_data;
    input date_var ;
    datalines;
        201605
        201606
        201607
        201608
        201609
        ;
run;

%macro Do_stuff(input_var);
    %put 'Line generates value ' &input_var;
%mend do_stuff;

data _null_;
    set start_data;
    call execute('%do_stuff('||date_var||')'  );
run;

Try this example and try modifying to meet your needs... From the "source" dataset we can use call symput() to assign a macro token to each observation (differentiated by the SAS automatic dataset variable n so My_token1, My_token2, etc.) Once you have a set of macro variables defined, just loop through them! 尝试此示例,然后尝试进行修改以满足您的需求...从“源”数据集中,我们可以使用调用symput()为每个观测值分配一个宏令牌(由SAS自动数据集变量n区分,因此为My_token1,My_token2等)。 )一旦定义了一组宏变量,就循环遍历它们! This program will print all the individual records from source to the SAS log: 该程序会将所有单独的记录从源打印到SAS日志:

data source;
do var=1000 to 1010;
output;
end;
run;

data _null_;
set source;
call symput(compress("My_token"||_n_),var);
run;

%put &my_token1  &my_token4;

%Macro neat;

%do this=1 %to 11;

*Check the log.;
%put &&My_token&this;

%end;

%mend;
%neat;

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

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