列出所有数据集中的变量以及变量的类型

时间:2019-01-10 16:53:34

标签: sas

我正在尝试制定一个程序,让我分配作业以进行SAS考试;我想列出所有数据集中的变量以及变量的类型;

libname printlib '...';
libname proclib '...';

proc datasets library=proclib memtype=data nolist;
copy out=printlib;
select delay internat;
run;

%macro printall(libname, worklib=work);
%local num i;
proc datasets library=&libname memtype=data nodetails;
contents out=&worklib..temp1(keep=memname) data=_all_ noprint;
run;

data _null_;
set &worklib..temp1 end=final;
by memname notsorted;
if last.memname;
n+1;
call symput('ds'||left(put(n, 8.)), trim(memname));
if final then
call symput('num', put(n, 8.));
run;

%do i=1 %to #

data work.data;
set &libname..&&ds&i;
var_type=vtype(name);
run;

proc contents data=work.data noprint out=data_info (keep=name varnum var_type);
run;

proc sort data=data_info out=variable_names(keep=name var_type);
by varnum;
run;

proc print data=work.variable_names;
title &libname..&&ds&i;
run;

%end;
%mend printall;

options nodate pageno=1 linesize=70 pagesize=60;
%printall(printlib)

结果应显示标题,即数据集名称,第一列应为变量名称,第二列应为变量类型(字符或数字)

现在它显示标题和变量名;但不是变量类型。我不太确定如何使变量类型显示在变量名称旁边。

3 个答案:

答案 0 :(得分:1)

为什么要这么复杂?

/usr/include/opencv4

答案 1 :(得分:1)

您还可以使用dictionary.columns。这给出了表名的列名和数据类型

   proc sql;
   create table want as 
   select cats( libname,'.', memname) as tablename,  name, type from 
   dictionary.columns;

答案 2 :(得分:0)

学习?您需要深深地嘲笑@Tom的答案。可以使用一种赋予人类可读的类型格式的格式来清理输出,并且可以使用#BYVALn构造使by变量值出现在标题语句中。

proc datasets noprint lib=work kill;
run;

data work.one(label="One is the loneliest number") work.two work.three;
  set sashelp.cars(obs=1);
run;

proc contents noprint data=work._all_ out=contents;
run;

proc format;
  value type 1='Num' 2='Char';
run;

proc sort data=contents;
  by libname memname varnum;

options nobyline;
title "Dataset: #byval1..#byval2 (#byval3)";

proc print noobs label data=contents;
  by libname memname memlabel;
  var varnum name type label;
  format type type.;
run;

title;