SAS:连接不同的数据集,同时保留单独的数据表名称 [英] SAS: concatenate different datasets while keeping the individual data table names

查看:14
本文介绍了SAS:连接不同的数据集,同时保留单独的数据表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 SAS 中连接多个数据集,并且正在寻找一种方法来将有关单个数据集名称的信息存储在最终堆叠的数据集中.

I'm trying to concatenate multiple datasets in SAS, and I'm looking for a way to store information about individual dataset names in the final stacked dataset.

例如.初始数据集是my_data_1"、abc"和xyz",每个都有var_1"和var_2"列.

For eg. initial data sets are "my_data_1", "abc" and "xyz", each with columns 'var_1' and 'var_2'.

我希望得到包含var_1"、var_2"和var_3"列的最终"数据集.其中var_3"包含值my_data_1"、abc"或xyz",具体取决于特定行来自哪个数据集.

I want to end up with "final" dataset with columns 'var_1', 'var_2' and 'var_3'. where 'var_3' contains values "my_data_1", "abc" or "xyz" depending on from which dataset a particular row came.

(为此我有一个笨拙的解决方案,即在所有单独的数据集中添加表名作为额外变量.但我有大约 100 个表要堆叠,我正在寻找一种有效的方法来做到这一点.)

(I have a cludgy solution for doing this i.e. adding table name as an extra variable in all individual datasets. But I have around 100 tables to be stacked and I'm looking for an efficient way to do this.)

推荐答案

设置每个数据集时使用in语句:

Use the in statement when you set each data set:

data final;
 set my_data_1(in=a) abc(in=b) xyc(in=c);
 if a then var_3='my_data_1';
 if b then var_3='abc';
 if c then var_3='xyz';
run;

这篇关于SAS:连接不同的数据集,同时保留单独的数据表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆