BookmarkSubscribeRSS Feed

날짜 형태 파일명에 대한 파일 존재성 체크 및 데이터 importing

Started ‎06-15-2020 by
Modified ‎06-15-2020 by
Views 82

* SAS에서 날짜 처리 예제(기타 날짜 처리 참고);

 

data back;     

     BASE_DT      = put(today(),yymmddn8.);

     BASE_BF7D_DT = put(today()-1-7,yymmddn8.);

     BASE_BF15D_DT = put(today()-1-15,yymmddn8.);

     base_date    = "'"||BASE_DT||"'";

     DEL_BF15D    = "'"||BASE_BF15D_DT||"'";

     first_date   = "'"||PUT(intnx('MONTH',input(BASE_DT,yymmdd10.),0,'beginning'),yymmddn8.)||"'";

     DEL_date   = "'"||PUT(intnx('MONTH',input(BASE_DT,yymmdd10.),-5,'beginning'),yymmddn8.)||"'";

 

     call symput('BASE_DT',BASE_DT); 

     call symput('base_date',base_date); 

     call symput('first_date',first_date); 

     call symput('BASE_BF7D_DT',BASE_BF7D_DT);

     call symput('DEL_BF15D',DEL_BF15D);

     call symput('DEL_date',DEL_date);

run;

%put &BASE_DT;

%put &base_date;

%put &first_date;

%put &BASE_BF7D_DT;

%PUT &DEL_BF15D;

%PUT &DEL_date;

 

 

* I:\SAS Temporary Files\back_20191217.txt 파일 읽어오기;

 

* back_20191217.txt 샘플데이터;

* 1 2 3

* 4 5 6

* 7 8 9

 

* 참고 예제 : https://communities.sas.com/t5/General-SAS-Programming/If-file-doesn-t-exist-read-the-last-one-filen...

* 참고 예제 : http://support.sas.com/kb/24/577.html;

 

 

* 파일이 저장된 폴더 위치와 해당 파일 지정;

%let testfile = %sysfunc(catt(I:\SAS Temporary Files\,back_,&BASE_DT,.txt));

%put &testfile=;

 

* 해당 파일이 존재하는 경우 파일을 import;​

%macro findit;                                 

  %if %sysfunc(fileexist("&testfile")) %then %do;  

    data one;                                    

      infile "&testfile";

      input a b c;                               

    run;                                         

  %end;                                          

  %else %put The file &testfile does not exist. ;

%mend;

    

/* invoke the macro */ 

%findit; 

Version history
Last update:
‎06-15-2020 04:19 AM
Updated by:
Contributors

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Article Labels
Article Tags