【发布时间】:2014-06-04 21:47:06
【问题描述】:
我正在编写一个 SAS 宏,它试图检查和更改格式,并检查和报告所有变量和所有变量的排除项(不应该存在的值)、有效值(应该只有 XYZ)等库中的数据集。
以下代码仅用于更改格式。
我创建了一个参考文件,它是 proc 内容的输出和一个包含每个变量规则的外部文件的组合。所以这个文件有数据集名称、变量名称和所有规则(格式、排除项、有效值、最小值、最大值等)
我无法让 SAS 遍历每个数据集中的每个变量 - 这段代码的最后一部分是我卡住的地方。
options mprint;
%macro reformat_var;
data _null_;
set SASDATA.Reference_File;
if Country='USA' then do;
call symput("SASData",SASData_Folder);
call symput("Country_Name",Country);
end;
run;
proc sql noprint;
select Data_Name, /*SAS dataset name */
Var_Name, /* Variable name */
Column_informat, /* current format of the variable in the data */
Column_format /* format I want to change to */
into : Data_List separated by ' ',
: Var_List separated by ' ',
: Informat_List separated by ' ',
: Format_List separated by ' '
from SASDATA.Reference_File;
quit;
proc sql noprint;
select count(filen)
into :cntfile
from sasdata._indexfile;
/*created in a prior step, indexfile has a list of all the SAS dataset names */
%if &cntfile>=1 %then %do;
select filen into :filen1-:filen%left(&cntfile)
from sasdata._indexfile;
%end;
quit;
/* Change date formats - this is where I am getting stuck – how do I check format
for each variable in each dataset using the macro variables (Data_List, Var_List,
Informat_list, Format_List) */
%do i=1 %to &cntfile;
data sasdata.&&filen&i;
set sasdata.&&filen&i;
%if &Country_Name='USA' and &Informat_list='mmddyy10.' %then %do;
format &Var_List &Format_list;
%end;
%end;
run;
%mend reformat_var;
%reformat_var;
【问题讨论】: