[英]How to drop columns with specific suffixes from a SAS table in SAS?
I have table in SAS Enterprise Guide like below:我在 SAS Enterprise Guide 中有如下表:
COL_DT | COL_5 | ... | COL_n
----------|--------|------|--------
10MAY2021 | 1 | ... | xxx
15DEC2021 | 0.5 | ... | xxx
09APR2020 | 12 | ... | xxx
... | ... | ... | ...
And I need to remove from above SAS table column which ends with: _DT, _ID, _CP
if columns with mentioned suffixes exist我需要从上面的 SAS 表中删除以以下结尾的列:
_DT, _ID, _CP
如果存在带有提到的后缀的列
Expected output:预期输出:
COL_5 | ... | COL_n
-------|------|-------
1 | ... | xxx
0.5 | ... | xxx
12 | ... | xxx
... | ... | ...
How can I do that in SAS Enterprise Guide?我如何在 SAS Enterprise Guide 中执行此操作?
Create sample data set创建示例数据集
data have;
input col1-col5 col_dt col_id col_cp;
cards;
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
;
run;
Create the list of columns to drop using the same technique as in your previous question使用与上一个问题相同的技术创建要删除的列列表
proc sql noprint;
select distinct name into :cols separated by ' '
from sashelp.vcolumn
where upcase(memname)='HAVE' and
(upcase(name) like '%^_DT' escape '^'
or upcase(name) like '%^_ID' escape '^'
or upcase(name) like '%^_CP' escape '^');
quit;
Drop the selected columns删除选定的列
data want;
set have(drop=&cols.);
run;
As a result因此
col1 col2 col3 col4 col5
1 2 3 4 5
9 10 11 12 13
Alternatively, you can use proc contents
instead of the SAS column view或者,您可以使用
proc contents
而不是 SAS 列视图
data have;
input col1-col5 col_dt col_id col_cp;
cards;
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
;
run;
proc contents data=have out=content noprint nodetails;run;
proc sql noprint;
select distinct name into :cols separated by ' '
from content
where upcase(memname)='HAVE' and
(upcase(name) like '%^_DT' escape '^'
or upcase(name) like '%^_ID' escape '^'
or upcase(name) like '%^_CP' escape '^');
quit;
data want;
set have(drop=&cols.);
run;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.