简体   繁体   English

如何将数据集名称作为列在SAS Macro中

[英]how to put the name of a dataset as a column in SAS Macro

I'm trying to write a macro. 我正在尝试编写一个宏。 The Marco is about output duplicates. Marco关于输出重复项。 And then append all of them into one dataset. 然后将它们全部添加到一个数据集中。 This dataset will have two columns: table name (which I select in one library), primary keys. 该数据集将包含两列:表名(我在一个库中选择),主键。 So, how can I get all the table names in Macro? 因此,如何获得Macro中的所有表名? I thought I can do: dataset='&data.' 我以为我可以做到:dataset ='&data。 as a new column into this dataset. 作为该数据集中的新列。 But the macro will treat all of them as &data. 但是宏会将它们全部视为&data。 instead of swap to the table names. 而不是交换到表名。

Thank you 谢谢

It was not easy to identify exactly what you are asking for but here are two starting points you can use. 确切地确定您的要求并不容易,但是这里有两个可以使用的起点。

You can use the :into option, to make a macro variable that holds a list of many things separated by a delimiter: 您可以使用:into选项,使宏变量包含由定界符分隔的许多内容的列表:

PROC SQL NOPRINT;
SELECT EMPID,
INTO :E1 SEPERATED BY “ , ”

FROM dset;
QUIT;

%PUT &E1;

You could also save numbered macro variables and a &varnum (number of datasets saved as a variable) and do an append within a loop (say you have the datasets listed var1 to varx): 您还可以保存编号的宏变量和&varnum(保存为变量的数据集数量),并在循环内进行追加(例如,您将数据集列在var1到varx中):

*needs to be in a macro;
%macro  loop_through();
    %do i = 1 %to &Varnum;

       /* proc append code here with data = &&var&i 
    (etc, &&var&i will resolve to &var1, &var2 and so on) */

    %end;
%mend;

%loop_through();

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

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