繁体   English   中英

sas:如何在2个数据集中创建一个包含不同变量列表的变量

[英]sas: how to create a variable containing a list of different variables in 2 datasets

我是SAS的新手。

我有2个数据集:set1和set2。 我想获取set2中而不是set1中的变量列表。

我知道我可以通过进行proc比较然后进行listvar来轻松查看它们,但是,我希望复制并粘贴整个变量列表,而不是从生成的报告中一一复制。

我想要一个包含所有用空格隔开的所有不同变量的列表的宏变量,或者以纯文本格式打印所有变量,以便我可以轻松地复制所有内容。

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;

获取变量名称列表,然后比较列表。

从概念上讲,查看数据集中最简单的方法是使用proc contents

proc contents data=set1 noprint out=content1 ; run;
proc contents data=set2 noprint out=content2 ; run;

现在,您只需要查找其中一个而不是另一个的名称。

一种简单的方法是使用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;

您也可以将列表推入宏变量而不是数据集。

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;

然后,您可以使用宏变量来生成其他代码。

data both;
   set set1(drop=&in1_not_in2) set2(drop=&in2_not_in1) ;
run;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM