SAS DOS命令 X 选项

1.

双双引号保证路径绝对被正确执行。

data a;
infile "dir /b "".\*.sas7bdat"" " pipe truncover;
input a $ ;
run;

第一个和最后一个双引号是一对

中间的四个就是双双引号

dir是列处来文件下的文件和文件夹信息,包括名字,大小,时间等

/b是限制只列出文件名和后缀名。

*表示,以.sas7bdat后缀的文件。

pipe必须得加,pipe是管道,把一个命令的结果,通过管道作为一个命令的输入。turncover详见sas 读取数据指针

 

/b/s 是把路径文件名后缀名字都列出来

 

2.

 SYSTEM

The SYSTEM function provides the same function and has the same syntax as the X statement, and it returns the command return code. 

 但是call system不返回执行成功与否情况,所以不推荐使用。可以使用 X 或 execute 或 %sysExec

X 或 %sysExec可以在任意位置使用。

data _null_;
infile "dir  /b "".\*.sas7bdat"" > "".\a.lst"" " pipe truncover;
run;

options noxwait;
X  "dir  /b "".\*.sas7bdat"" > "".\a.lst"" ";

data _null_;
call system(" del /s/q ""./a.lst"" ");
run;

 

 

data source_infile;
    set source;
    length newname _n_c $200;
    name = cats("./",name);
    newname = tranwrd(name,".sas",".txt");
    _n_c = strip(put(_n_,best.));
    call execute (strip("filename sname") || _n_c || " " || quote(name) || " encoding = any  lrecl = 300 ;");
    call execute (strip("filename tname") || _n_c || " " || quote(newname) || "encoding = any lrecl = 300 ;");
run;

option xwait;

 

 

    call execute (strip("filename sname") || _n_c || " " || quote(name) || " encoding = any  lrecl = 300 ;");

 

    rc = fcopy(cats("sname",_n_c),cats("tname",_n_c) );
    rc = system( catx(' copy ',cats("sname",_n_c),cats("tname",_n_c) ) );
    rc = system( ' rename _1.sas _1.txt' );

NOXWAIT: 执行完直接关闭黑窗口

fcopy 把一个文件内容copy到另外一个文件

system()也是copy到另外一个文件。执行语句是  copy a.sas b.txt   举例

system() rename 是改变文件后缀名。

这几种方式都会改变文件时间戳

3.

解决方法:直接运行bat

 

rename *.sas *.txt

保存为bat直接运行。

 

4. 

 命令:

options noxwait;

1. X "rd    /s/q  foldername";   

  rd: 移除文件夹。Remove Directory

  /s: 目录和文件一块删除

  /q: 直接删除,不用确认

2. data _null_;
a = sleep(5);

NewDir = dcreate("aa","./");  
run;

休眠5秒,新建文件夹

3. X ”mkdir foldername“; 新建文件夹

4. X "dir /b/s "".\"" > "".\a.lst"" "; 把当前folder下的所有文件路径名字写入a.lst

5. X " del  "" .\a.lst"" "; 删除 a.lst文件

call system(" del  "" .\a.lst"" "); 在DATA步调动CMD命令,删除文件,和X选项效果相同。

 

posted @ 2021-10-31 13:34  Iving  阅读(873)  评论(0编辑  收藏  举报