import - 在 SAS 中使用嵌套的 Do-Loop 导入 Zip 文件时遇到问题
问题描述
我正在尝试导入 104 个 zip 文件,每个文件包含大约 30 个 excel 文件。我创建了一个 excel 文件,其中包含我要导入的所有 zip 文件的名称 (NYISO_Names)。第一个 do 循环查看所有 zip 文件的名称。接下来,我创建了每个 zip 文件内容的列表。第二个循环遍历内容。
至此,代码导入了第一个 zip 文件(30 个 excel 工作簿);但是,它永远不会移动到剩余的 zip 文件。do-loops的嵌套方式有问题吗?
%macro test;
%do i=1 %to 6;
%put ---&i.;
%let Iteration = &i.;
data abs;
set NYISO_Names;
if _n_ =&i. then call symput("FileName", strip(FileName));
if _n_ = &i. then call symput("Path", strip(Path));
run;
filename inzip zip "G:Desktop\&FileName.";
/* Read the "members" (files) from the ZIP file */
data Contents_&i.(keep=memname isFolder sheet);
length memname $200 isFolder 8;
fid=dopen("inzip");
if fid=0 then
stop;
memcount=dnum(fid);
do i=1 to memcount;
memname=dread(fid,i);
sheet = substr(memname, 1, length(memname)-4);
/* check for trailing / in folder name */
isFolder = (first(reverse(trim(memname)))='/');
output;
end;
rc=dclose(fid);
run;
DATA _NULL_; IF 0 THEN SET Contents_1 NOBS=X; CALL SYMPUT('RECCOUNT',X); STOP; RUN;
%do i = 1 %to &RECCOUNT;
data abs2;
set Contents_&Iteration.;
if _n_ =&i. then call symput("memname", strip(memname));
if _n_ =&i. then call symput("sheet", strip(sheet));
run;
/* identify a temp folder in the WORK directory */
filename xl "%sysfunc(getoption(work))/&memname." ;
/* hat tip: "data _null_" on SAS-L */
data _null_;
/* using member syntax here */
infile inzip(&memname.)
lrecl=256 recfm=F length=length eof=eof ;
file xl lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
proc import datafile=xl dbms=csv out=Test&i. replace;
run;
%end;
%end;
%mend;
%test();
任何帮助将不胜感激。
解决方案
您的嵌套%do
循环使用相同的索引变量i
尝试对手头的问题使用具有语义意义的不同变量
%macro test;
…
%do iterationIndex = 1 %to 6;
…
%do referenceIndex = 1 %to &REFCOUNT;
…
%end;
%end;
…
%mend;
%test;
推荐阅读
- java - 在具有重复元素的旋转排序数组中查找元素
- javascript - 在react redux中接收数据后调用另一个函数内部的函数
- excel - 在 Excel 上使用名称对项目进行分类
- c# - 如何在 [Authorize] 属性上设置断点
- typescript - 如何将空检查提取到方法中并获得有效的空类型检查?
- r - 根据条件选择 data.table 列,在 by
- reactjs - 哪个更好地找到屏幕的宽度
- python-3.x - 我可以直接在python中调用对象的值吗?所以在这种情况下我没有得到对象实例?
- oracle - oracle 12.2.0.1 中的命名空间 sys_Session_roles 在 sql 查询中工作,但不在 plsql 块内
- python - 如何不基于 __new__ 方法运行 init