[英]sas: how to create a variable containing a list of different variables in 2 datasets
I'm kinda new to SAS. 我是SAS的新手。
I have 2 datasets: set1 and set2. 我有2个数据集:set1和set2。 I'd like to get a list of variables that's in set2 but not in set1. 我想获取set2中而不是set1中的变量列表。
I know I can easily see them by doing proc compare and then listvar, however, i wish to copy&paste the whole list of different variables instead of copying one by one from the report generated. 我知道我可以通过进行proc比较然后进行listvar来轻松查看它们,但是,我希望复制并粘贴整个变量列表,而不是从生成的报告中一一复制。
i want either a macro variable containing a list of all different variables separated by space, or printing out all variables in plain texts that I can easily copy everything. 我想要一个包含所有用空格隔开的所有不同变量的列表的宏变量,或者以纯文本格式打印所有变量,以便我可以轻松地复制所有内容。
proc contents data=set1 out=cols1;
proc contents data=set2 out=cols2;
data common;
merge cols1 (in=a) cols2 (in=b);
by name;
if not a and b;
keep name;
run;
proc sql;
select name into :commoncols separated by ','
from work.common;
quit;
Get the list of variable names and then compare the lists. 获取变量名称列表,然后比较列表。
Conceptually the simplest way see what is in a dataset is to use proc contents
. 从概念上讲,查看数据集中最简单的方法是使用proc contents
。
proc contents data=set1 noprint out=content1 ; run;
proc contents data=set2 noprint out=content2 ; run;
Now you just need to find the names that are in one and not the other. 现在,您只需要查找其中一个而不是另一个的名称。
An easy way is with PROC SQL set operations. 一种简单的方法是使用PROC SQL设置操作。
proc sql ;
create table in1_not_in2 as
select name from content1
where upcase(name) not in (select upcase(name) from content2)
;
create table in2_not_in1 as
select name from content2
where upcase(name) not in (select upcase(name) from content1)
;
quit;
You could also push the lists into macro variables instead of datasets. 您也可以将列表推入宏变量而不是数据集。
proc sql noprint ;
select name from content1
into :in1_not_in2 separated by ' '
where upcase(name) not in (select upcase(name) from content2)
;
select name from content2
into :in2_not_in1 separated by ' '
where upcase(name) not in (select upcase(name) from content1)
;
quit;
Then you could use the macro variables to generate other code. 然后,您可以使用宏变量来生成其他代码。
data both;
set set1(drop=&in1_not_in2) set2(drop=&in2_not_in1) ;
run;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.