数据集列名到宏变量中 [英] data set column names into macro variable(s)
本文介绍了数据集列名到宏变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将给定数据集的所有列名放入宏变量的最简单方法是什么?
What is the simplest way to put all column names of a given dataset into a macro variable?
另一个问题,我应该如何将所有数字"列的名称放入一个宏变量中,并将所有字符列的名称放入另一个宏变量中?
Another question, how should I put names of all "numeric" columns into one macro variable and names of all character columns into another macro variable?
推荐答案
如果您需要对多个表执行此操作,那么您可以尝试为此目的定义一个宏,例如:
If you need to do this for a number of tables then you could try defining a macro for that purpose, e.g.:
%macro get_cols(lib,mem,mvar,type);
%global &mvar;
proc sql noprint;
select
name
into
:&mvar separated by ' '
from
dictionary.columns
where
libname eq upcase("&lib")
and memname eq upcase("&mem")
%if %upcase(&type) ne ALL %then
and upcase(type) eq upcase("&type");
;
quit;
%put &mvar = &&&mvar;
%mend get_cols;
然后您可以根据需要调用它:
Then you could call it, as required:
/* character variables */
%get_cols(sashelp,class,cvars,char);
/* numeric variables */
%get_cols(sashelp,class,nvars,num);
/* all variables */
%get_cols(sashelp,class,vars,all);
这篇关于数据集列名到宏变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文