2017-04-07 2 views
0

work.Directories.data의 형식으로 디렉토리 목록을 가지고 있습니다 (변수가 디렉토리 임).매크로 명령을 사용하여 데이터 세트의 여러 디렉토리 검색

C : \ importantfolder \ 하위 폴더 나 각 디렉토리의 내용을 찾아 새로운 데이터 세트를 만들기 위해 그들을 결합 할

\ 각 행은 다음과 같습니다 문자열이 포함되어 있습니다. 다음은 지금까지 내가 가지고있는 것입니다 :

%macro ScanDirec(STRING=); 
    filename temptree pipe 'dir "&STRING" /s /b' lrecl=5000; 

    data SmallList; 
     infile temptree truncover; 
     input dirlist $char1000.; 
    run; 

    data BigList; 
     set BigList SmallList; 
    run; 
%mend ScanDirec; 

data SmallList; 
run; 
data BigList; 
run; 

data _null_; 
    set Directories; 
    call execute('%ScanDirectories('||directory||')'); 
run; 

나는 심각한 문제가 발생하지만, 제 코드는 꽤 해롭습니다. 이슈가 뭐야?

+0

의 사용 가능한 복제가 [왜 내 매크로 변수가 해결되지 않습니다?] (http://stackoverflow.com/questions/27946244/why-wont-my-macro-variable-resolve) – Joe

+0

지긋 지긋한의 dupehammer은 '아무튼 [tag : sas]가 처음에는 질문에 있지 않을 때 작동합니다. 어쨌든 - OP - 파이프가 작은 따옴표 안에 있습니다. – Joe

+1

그리고 나중에 참조 할 - "심각한 문제가 생겼다"는 것은 우리가보고 싶은 것이 아니기 때문에 오류 메시지를보고 싶습니다. 그렇지 않으면 좋은 질문입니다. – Joe

답변

1

오류 메시지는 매우 간단합니다.

1 data test ; 
2  infile 'dir "&STRING" /s /b' pipe truncover; 
3  input dirlist $char1000.; 
4 run; 

NOTE: The infile 'dir "&STRING" /s /b' is: 
     Unnamed Pipe Access Device, 
     PROCESS=dir "&STRING" /s /b,RECFM=V, 
     LRECL=32767 

Stderr output: 
File Not Found 
NOTE: 0 records were read from the infile 'dir "&STRING" /s /b'. 
NOTE: The data set WORK.TEST has 0 observations and 1 variables. 
NOTE: DATA statement used (Total process time): 
     real time   0.99 seconds 
     cpu time   0.04 seconds 

"&STRING"이라는 파일을 찾을 수 없습니다.

SAS가 매크로 표현식을 해결하도록하려면 문자열 주위에 큰 따옴표를 사용하십시오.

"dir ""$STRING"" /s /b" 

매크로를 완전히 피하십시오.

data BigList; 
    set Directories; 
    length cmd $500 ; 
    cmd = catx(' ','dir',quote(trim(directory)),'/s /b'); 
    infile cmd pipe filevar=cmd truncover end=eof; 
    do while (not eof); 
    input dirlist $char1000.; 
    output; 
    end; 
run; 
+0

내가 원했던 것보다 훌륭하고 훌륭하다. 고마워요. – Prototank

관련 문제