楼主: Tigflanker
1824 3

[问答] 如何对一个库内的所有数据集进行set [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

威望
0
论坛币
2321 个
通用积分
9.9128
学术水平
179 点
热心指数
194 点
信用等级
167 点
经验
27443 点
帖子
622
精华
0
在线时间
851 小时
注册时间
2011-3-27
最后登录
2023-5-14

楼主
Tigflanker 发表于 2013-6-14 23:35:43 |AI写论文
100论坛币
请各位老师帮忙,有个问题个人觉得较困难。

问题背景:例如有个库,叫做lib,里面有20个数据集,名字各异,例如:tom,jerry,。。。,susan;这20个数据集中的变量大体相同,但也有差异。

问题:我现在想找一个变量,例如叫做:age。我该如何找呢?(请别用枚举法,或者请思考这是200个数据集)

-----------------------------------------------------------------------------------------

我的解决方法(较笨):

将每个数据集用proc contents过程做成属性数据集,例如:tom_att,jerry_att,。。。,susan_att,并将这每个属性数据集加一列自己数据集名称的变量,作为标识;然后将这些数据集进行set;最后理所应当的用where或者sql进行列表输出。

问题:

1.我希望用宏解决,可是如何将这个lib库里面的不同名称数据集全部调用呢?有无类似的自动宏变量?(已用proc datasets自行解决,谢谢。)

2.针对该问题,有无更好解决方法?

感谢感谢。

最佳答案

bobguy 查看完整内容

Here is a solution for you. The variable types should be same in all data sets. %let var=DENSITY; %let lib=MAPS; proc sql noprint; select catt(libname,'.', memname, '(keep=DENSITY)' ) into: dsnlist separated by ' ' from dictionary.columns where libname="&lib" and name="&var"; ; quit; data _null_; if &sqlobs>0 then do; call execute("data need; set &dsnlist; run;"); ...
关键词:Set 数据集 datasets contents dataset 如何
Bye SAS.
若有缘,能重聚。

沙发
bobguy 发表于 2013-6-14 23:35:44
Here is a solution for you. The variable types should be same in all data sets.

%let var=DENSITY;
%let lib=MAPS;

proc sql noprint;
select catt(libname,'.', memname, '(keep=DENSITY)' )
                into: dsnlist separated by ' '
from dictionary.columns
where libname="&lib" and name="&var";
;
quit;

data _null_;
  if &sqlobs>0 then do;
    call execute("data need; set &dsnlist; run;");
  end;
  else put "there is no variable &var found in library &lib";
run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
hopewell + 1 + 1 + 1 我很赞同

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

藤椅
邓贵大 发表于 2013-6-14 23:51:28
sashelp.vcolumn or dictionary.columns has all you need
http://support.sas.com/resources ... ings10/155-2010.pdf
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

板凳
Tigflanker 发表于 2013-6-15 00:07:53
邓贵大 发表于 2013-6-14 23:51
sashelp.vcolumn or dictionary.columns has all you need
http://support.sas.com/resources/papers/proc ...
Thank you. I will try the method which mentioned in the paper latter.
Bye SAS.
若有缘,能重聚。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-4 05:06