【发布时间】:2023-03-19 02:32:01
【问题描述】:
SAS 的初学者。我想从我的输入中删除一个变量列表。该列表本身作为观察值存在于另一个数据集中。在进行了一些谷歌搜索后,我发现了这篇关于该主题的优秀论文。
http://www2.sas.com/proceedings/sugi30/028-30.pdf
所以我使用以下代码在宏变量中创建一个列表:
/*make a list of variables as a macro variable */
data _null_;
length allvars $1000;
retain allvars ' ';
set to_drop end=eof;
allvars = trim(left(allvars))||' '||left(_name_);
if eof then call symput('varlist', allvars);
run;
我现在面临三个问题:
1) 当我 %PUT &VARLIST 时,日志只显示 31 个变量,而我的列表实际上是 2000 多个变量。
2)我不清楚声明:trim(left(allvars)) || ' ' || left(_name_); 在做什么。我知道 trim 删除了前导空格, left 是对齐左字符串,但无法理解完整的语句。
3) 然后我尝试使用以下代码从我的 inputds 中删除它,我收到一条警告消息并且没有发生删除:
data inputds2 (drop = &varlist);
set inputds;
run;
WARNING: The variable avg_weighted in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 43662 observations read from the data set WORK.INPUTDS.
NOTE: The data set WORK.INPUTDS2 has 43662 observations and 3465 variables.
实际上,我的变量名称如下所示:avg_weighted_minutes_view_3739 avg_weighted_minutes_view_7963 avg_weighted_minutes_view_(XXXX) 最后 4 位数字是随机的。这是 SAS 生成的名称,因为我的标签包含空格。
编辑:尝试使用另一个部分工作的代码 - 它列出了一个更大的列表 - &VARLIST 宏变量中的 2000 多个变量中的大约 1000 个。
data _null_;
set to_drop;
call symput('varlist',trim(
resolve('&varlist')
)||' '||trim(_name_));
run;
%put &varlist;
【问题讨论】: