如何在数据步骤中获取数据集标签?

How to get dataset label in a data step?

我想获取set语句中的数据集的标签,但我没有找到一个漂亮的方法。

我试过这个:

data test;
    set sashelp.class;
    rc = open("sashelp.class");
    label = attrc(rc,"label");
    rc = close(rc);
run;

它可以工作,但也有一个弱点,我必须在 open() 函数中写数据集的名称。
我正在寻找一种更好的方法来代替手动编写,因为我有许多类似的步骤。

我也试过&syslast,但是没用。请问还有别的办法吗?

可能是 INDSNAME

18   data _null_;
19      set sashelp.class(obs=2 drop=_all_) sashelp.shoes(obs=2 drop=_all_)indsname=indsname;
20      retain label;
21      if indsname ne lag(indsname) then do;
22         rc = open(indsname); label=attrc(rc,"label"); rc=close(rc);
23         end;
24      put _all_;
25
26      run;

indsname=SASHELP.CLASS label=Student Data rc=0 _ERROR_=0 _N_=1
indsname=SASHELP.CLASS label=Student Data rc=. _ERROR_=0 _N_=2
indsname=SASHELP.SHOES label=Fictitious Shoe Company Data rc=0 _ERROR_=0 _N_=3
indsname=SASHELP.SHOES label=Fictitious Shoe Company Data rc=. _ERROR_=0 _N_=4

IMPLMAC 允许的语句样式宏是否有资格参加 SAS 选美比赛?

SET 语句重新用作语句样式宏,它发出包含正常 SET 语句的源代码和通过 ATTRC 检索的数据集标签的数据步骤变量赋值。

示例:

%macro SET(data) / STMT;
  options IMPLMAC = 0; %* turn off implmac so following SET is normal token;
  SET &data;
  options IMPLMAC = 1; %* turn on implac so subsequent SET invoke this macro;
  %local id;
  %let id = %sysfunc(open(&data));
  %if (&id) %then %do;
    DSLABEL = %sysfunc(quote(%sysfunc(ATTRC(&ID,LABEL))));
    %let id = %sysfunc(close(&id));
  %end;
%mend;

data have(label="This is the data set I ""have""");
  x=1;
run;


options IMPLMAC=1 MPRINT;

data _null_;
  SET HAVE;
run;

options IMPLMAC=0;