xpt2sas(.xpt文件批量转为.sas7dbat)

编程入门 行业动态 更新时间:2024-10-08 19:49:06

xpt2sas(.xpt<a href=https://www.elefans.com/category/jswz/34/1768119.html style=文件批量转为.sas7dbat)"/>

xpt2sas(.xpt文件批量转为.sas7dbat)

.xpt文件批量转为.sas7dbat

  • 前言
  • 一、文档目录举例
  • 二、方法一(SAS EG 8.3环境下)
  • 三、方法二(SAS9.4环境下)


前言

提供了两种不同编码环境下xport转sas的宏脚本xpt2sas,新建一个名为raw的文件夹,再内嵌一个名为xpt的文件夹,将需要转换的

xpt文件放置在xpt目录下,运行代码后,生成的.sas7dbat文件将批量出现在raw目录下


一、文档目录举例

示例:在如下文档目录前提下编码

二、方法一(SAS EG 8.3环境下)

只需要替换url中的file其他代码不用动

%macro xpt2sas;
%let url=%str(\\file\raw); \*file需要更换为指定目录如:\\10.10.1.95\filesever\project\task*\
libname raw "&url.";data _import;
length file line $200;
/* Define a filename pointing to the directory */
rc = filename("myDir", "&url.\xpt");
/* Open the directory, get directory id number */
dirId = dopen("myDir");
if dirId > 0 then do;/* dnum() : nb of files in directory */do i = 1 to dnum(dirId);/* Read the ith file name from directory */file = dread(dirId, i);line =cats("%","xpt2loc","(libref=raw,filespec='","&url.","\xpt\",file,"');");if length(file) > 0 then output;end;/* Close the open directory */rc = dclose(dirId);end;
drop rc dirId i file;
run;
data _null_;set _import end=eof;file "&url.\xpt\xpt2loc.sas" dlm="" lrecl=32000;put line;
run;
%include "&url.\xpt\xpt2loc.sas";
%mend;
%xpt2sas;

三、方法二(SAS9.4环境下)


%macro xpt2sas;
data _null_;call system("cd \file\raw\xpt"); \*file需要更换为指定目录如:D:\filesever\project\task*\
run;
filename _dir pipe 'ls -la *.xpt' ; /*linux:ls,window:dir*/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=raw ,filespec='||"'"||'\file\raw/xpt\'||strip(_file)||"'"||');';output;
run;filename outfile "\file\raw\xpt2lo.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 raw '/file/raw/';
%include '/file/raw/xpt2loc.sas';

更多推荐

xpt2sas(.xpt文件批量转为.sas7dbat)

本文发布于:2024-03-23 16:08:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1740143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件批量   xpt2sas   xpt   sas7dbat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!