xpt2sas(批量xport檔案轉為sas檔案)
阿新 • • 發佈:2020-12-07
Folder 如下:
xpt2sas 程式碼如下:
/** 檔案路徑需修改 **/ %macro xpt2sas; data _null_; call system("cd /file/raw/xpt"); run; filename _dir pipe 'ls -la *.xpt' ; data _import(keep=line); length _dirline $200; length _file $20; length line $200.; infile _dir recfm=v lrecl=200 truncover ; input _dirline $1-200 ; _file = scan(_dirline, 9, " "); line = '%xpt2loc(libref=rawdata,filespec='||"'"||'/file/raw/xpt/'||strip(_file)||"'"||');';output; run; filename outfile "/file/raw/xpt2loc.sas"; data _null_; set _import end=eof; file outfile dlm="" lrecl=32000; put line; run; x "perl -i -pe 's/\n/\r\n/g' /file/raw/xpt2loc.sas"; filename outfile clear; %mend; %xpt2sas; libname rawdata '/file/raw/'; %include '/file/raw/xpt2loc.sas';