简体   繁体   English

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

[英]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.

相关问题 SAS附加2个具有不同变量的数据集 - SAS appending 2 datasets with different variables 如何创建2个包含上一个平均值的sas数据集 - How to create 2 sas datasets containing the avg of a previous one SAS:如何检查两个数据集中的相同变量是否不同? - SAS: how to check if the same variable from two datasets are different? SAS:如何基于宏变量在循环中创建数据集 - SAS: How to create datasets in loop based on macro variable 是否可以在SAS中堆叠具有不同变量的数据集? - Is it possible to stack datasets with different variables in SAS? 如何使用 SAS 删除包含 SAS 数据集的外部文件夹 - How to delete external folders containing SAS datasets, using SAS 根据包含密码本的单独数据集中的变量更改一个数据集中的 SAS 变量标签/属性 - PROC SQL? 处理数据集? - Changing SAS variable labels/attributes in one dataset based on variables in a separate dataset containing a codebook - PROC SQL? PROC DATASETS? SAS包含特殊字符的变量列表 - SAS List of variables containing special characters 如何从SAS中的同一文本文件导入具有变量变量的不同数据集 - How to import different datasets with differents variables from the same text file in SAS SAS:如何获得不同数量的数据集的并集? - SAS: How to get the union of a different number of datasets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM