Sas 如何在数据步骤中获取数据集标签?
我想得到set语句中的dataset的标签,但是我还没有找到一个漂亮的方法 我试过这个:Sas 如何在数据步骤中获取数据集标签?,sas,attr,Sas,Attr,我想得到set语句中的dataset的标签,但是我还没有找到一个漂亮的方法 我试过这个: data test; set sashelp.class; rc = open("sashelp.class"); label = attrc(rc,"label"); rc = close(rc); run; 它可以工作,但也有一个弱点,我必须在open函数中写入数据集的名称。 我正在寻找一种更好的方法来代替手工编写,因为我有几十个类似的步骤 我也尝试过&syslast,
data test;
set sashelp.class;
rc = open("sashelp.class");
label = attrc(rc,"label");
rc = close(rc);
run;
它可以工作,但也有一个弱点,我必须在open函数中写入数据集的名称。
我正在寻找一种更好的方法来代替手工编写,因为我有几十个类似的步骤
我也尝试过&syslast,但它不起作用。还有别的办法吗?也许是因为我
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
也许是因为我
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语句重新调整为语句样式的宏,该宏发出源代码,其中包含通过ATTR检索的数据集标签的正常SET语句和数据步变量赋值 例如:
%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;
IMPLMAC允许的语句式宏是否符合SAS选美大赛的条件 将SET语句重新调整为语句样式的宏,该宏发出源代码,其中包含通过ATTR检索的数据集标签的正常SET语句和数据步变量赋值 例如:
%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;
哦,有一件事忘了。set语句中只有一个数据集。我不知道有什么方法可以做到这一点,但有人可能会让我大吃一惊。如果有一种方法可以确定当前打开的数据集的名称,那么它必须处理大量与set语句、多个set语句、条件set语句等上的多个数据集相关的边缘情况。我只需要执行“%let ds=sashelp.class;”然后用“&ds”替换这两个实例。当然,您也可以在一个单独的步骤中从DICTIONARY.TABLES视图中获取标签,如果这更干净的话。哦,有一件事忘了。set语句中只有一个数据集。我不知道有什么方法可以做到这一点,但有人可能会让我大吃一惊。如果有一种方法可以确定当前打开的数据集的名称,那么它必须处理大量与set语句、多个set语句、条件set语句等上的多个数据集相关的边缘情况。我只需要执行“%let ds=sashelp.class;”在您的步骤之前,然后用“&ds”替换这两个实例。当然,您也可以在单独的步骤中从DICTIONARY.TABLES视图中获取标签,如果这更干净的话。以前从未看到过这种情况。您能告诉我语句样式宏与名称样式宏相比有什么优势吗?在我看来,没有。当然也有保持背部兼容性的方法。也许在早期SAS的迷雾中,开发该功能是为了模拟或扩展过程的“语法”。语句样式宏的概念与命令样式宏有相似之处。Richard,你真的很有知识。以前从未见过这种情况。你能告诉我,与名称样式宏相比,语句样式宏有什么优势吗?在我看来,没有。当然也有保持背部兼容性的方法。也许在早期SAS的迷雾中,开发该功能是为了模拟或扩展过程的“语法”。语句式宏的概念与命令式宏有相似之处。Richard,你真的很有知识。