BookmarkSubscribeRSS Feed

SAS를 활용한 특정 디렉토리 파일이름 읽어오기

Started ‎06-12-2020 by
Modified ‎06-12-2020 by
Views 236

아주 오랜만에 글쓰기 하네요. 

 

가끔 제목과 관련된 작업이 필요해서 간단히 만들어 사용하고 있는 프로그램입니다. 

->directory, filetype만 지정해 주면 파일이름이 데이터로 저장됩니다.

참조하세요!!!

 

 

/*LIBNAME _MYjob "D:\_작업창고\_1분석작업창고\data" ;*/

%LET LIB = _MYJOB ;

 

/* 파일이름을 가져올 directory 지정 */

%LET FilePath = %STR(C:\Program Files (x86)\SAS\JMP\12\Samples\Data\Time Series) ;

 

/* 가져올 파일의 형식 지정 */

%let FileType = %UPCASE(jmp) ;    /* 형식 미지정 시에는 => %UPCASE() ; */

 

%macro m_GetFile (FilePath) ; 

 

data fileList;

     length FileName $ 100 ; /* 파일명 길이 할당*/

     rc=filename("myDir","&FilePath");

     if rc=0 then do;

        * 디렉토리 Open;

        did=dopen("myDir");

        if did > 0 then do;

           * 디렉토리의 멤버(파일) 갯수 반환;

           memcount=dnum(did);

           do i=1 to memcount;

           * 디렉터리의 멤버(파일) 이름 반환;

              FileName=dread(did,i);

              output;

           end;

           rc=dclose(did);

        end;

        rc=filename('myDir',' ');

      end;

   keep FileName ;

run;

 

/* 특정 형식 파일 이름명 한정 */

data fileList_Out ;

format no ;

set  fileList;

 

extension = scan(FileName,-1,".") ;

if FileName = extension then extension = "" ;

 

if "&FileType" =""  then goto skip_where ;

 

   where UPCASE(FileName) contains "&FileType" ; 

 

skip_where: 

no = _n_ ;

   call symput("no_file_total" , _n_) ; 

run;

 

%put 전체 파일갯수 : &no_file_total ;

 

%mend ;

 

%m_GetFile (&FilePath ) ;  

Version history
Last update:
‎06-12-2020 05:21 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Article Labels
Article Tags