如何一次遍历数据集一个行/一个观察

时间:2019-02-08 21:36:38

标签: sas

我有一个创建的数据集

filename tmp pipe 'dir "C:\Temp1\*.txt*" /b /s';

data Full;
    infile tmp dlm="\";
    length Path $2000 Path2 $2000 Path3 $2000 Path4 $2000 FileName $2000;
    input Path Path2 Path3 Path4 FileName;
run;

结果如下:

C:\Temp1\test - Copy (12).txt
C:\Temp1\test - Copy.txt
C:\Temp1\test.txt
C:\Temp1\test - Copy (2).txt
C:\Temp1\test - Copy (3).txt
C:\Temp1\test - Copy (4).txt
C:\Temp1\test - Copy (5).txt
C:\Temp1\test - Copy (6).txt
C:\Temp1\test - Copy (7).txt
C:\Temp1\test - Copy (8).txt
C:\Temp1\test - Copy (9).txt
C:\Temp1\test - Copy (10).txt
C:\Temp1\test - Copy (11).txt

我正在使用下面的代码

options noxwait;
    data _null_;
    set Full nobs=nobs;
    i = 1;
    do while (i < nobs);
    set Full point=i;
    %let oldfile = <<<THIS IS WHERE I WANT THE DATA TO BE PULLED TO>>>;
    %let newfile = C:\Temp2\;
      rc= system("move &oldfile &newfile ");
      i = i + 1;
    put rc=;
    end;
    run;

基本上,我想遍历我的“完整”数据集并将每一行设置为oldfile。

我需要在代码中修复什么?

1 个答案:

答案 0 :(得分:2)

DATA步骤已经是数据集中所有行的隐式循环。您不需要其他外部机构来控制。另外,如果刚开始,请不要混用数据步骤范围和宏范围变量。

未经测试的示例:

data Full;
    infile tmp;
    input; * read whole line into _infile_ buffer;
    filename = _infile_; * transfer buffer to variable;
run;

data _null_;
  set full;
  command = "move " || quote(trim(filename)) || " " || quote(trim("C:\Temp2\"));
  rc = system(command);
run;