楼主: davil2000
13877 35

[原创博文] MS-DOS命令在SAS环境中的应用 [推广有奖]

院士

98%

还不是VIP/贵宾

-

TA的文库  其他...

☆大数据时代文库☆

威望
4
论坛币
29697 个
通用积分
13.2845
学术水平
1172 点
热心指数
1121 点
信用等级
1143 点
经验
96908 点
帖子
2694
精华
19
在线时间
3003 小时
注册时间
2004-10-31
最后登录
2022-6-10

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
options noxwait;
/*  create a directory with the system function and mkdir command*/
data _null_;
  rc = system('mkdir D:\Docs\z');
  put rc=;
run;

/*change default directory*/
x 'cd D:\Docs\z';

/*export a data file to the default directory*/

proc export data=sashelp.prdsale
outfile="test.csv" dbms=csv replace;   
run;

/* display the directory with the pipe option and dir command*/
filename fileref PIPE 'dir /q  D:\Docs\z';
data _null_;
infile fileref;
input ;
put _infile_;
run;


/* delete files and subdir in a directory with rd command*/
data _null_;
  rc = system('rd/s/q D:\Docs\z');
  put rc=;
run;

/*---  /s    Removes all directories and files in the specified directory in  ---*/
/*---   addition to the directory itself. Used to remove a directory tree. ---*/
/*---  /q    Quiet mode, do not ask if ok to remove a directory tree with /s. ---*/



other commands for managing directory and the contents

del /q "filename"
for deleting file(s) in a directory without prompting

ren *.csv *.txt
for changing the extensions of all the file names in the current directory




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:DOS Extensions directory Extension specified function default command replace display

已有 6 人评分学术水平 热心指数 信用等级 收起 理由
a6566792 + 1 + 1 + 1 精彩帖子
pobel + 3 + 3 + 3 精彩帖子
南海游客 + 5 + 5 + 5 精彩帖子
420948492 + 1 + 1 精彩帖子
zhentao + 1 + 1 + 1 非常好。
zhukovasky + 1 精彩帖子膜拜大神

总评分: 学术水平 + 12  热心指数 + 11  信用等级 + 10   查看全部评分

本帖被以下文库推荐

R是万能的,SAS是不可战胜的!
沙发
zhukovasky 发表于 2012-12-1 20:47:43 |只看作者 |坛友微信交流群
膜拜大神,每一次都是提高啊!
za rujina!

使用道具

藤椅
Bridgenc 发表于 2012-12-1 22:35:32 |只看作者 |坛友微信交流群
very useful, thanks a lot

使用道具

板凳
Eternal0601 发表于 2012-12-9 13:14:46 |只看作者 |坛友微信交流群
膜拜下

使用道具

报纸
Eternal0601 发表于 2012-12-16 15:43:26 |只看作者 |坛友微信交流群
弱弱地问下
/* display the directory with the pipe option and dir command*/
filename fileref PIPE 'dir /q  D:\Docs\z';
data _null_;
infile fileref;
input ;
put _infile_;
run;
这部分有啥特别用处吗?主要还是显示文件夹的信息吧

使用道具

地板
davil2000 发表于 2012-12-16 16:04:39 |只看作者 |坛友微信交流群
Eternal0601 发表于 2012-12-16 15:43
弱弱地问下
/* display the directory with the pipe option and dir command*/
filename fileref PIPE ' ...
yeah! u r right.
R是万能的,SAS是不可战胜的!

使用道具

7
Tigflanker 发表于 2012-12-16 17:24:16 |只看作者 |坛友微信交流群
hehe,给大神您提供我宏里面的几个小语句,望能贡献,并提供点点提示:

宏参数&fn:TXT文本生成路径(包括文件名)
&path:文本输出路径
&opti:选项

%macro...

  1. %if &opti<2 %then %goto fn;
  2. %else %if &opti=2 %then %let opti="&fn at 5s";     //运行上面宏后5秒内打开TXT结果
  3. %else %if &opti=3 %then %let opti="start &path & taskkill /F /IM sas.exe & exit";          //运行上面宏后结束SAS(多SAS运行则全部关闭)
  4. %else %if &opti=4 %then %let opti="shutdown /s /f";           //运行结束后关机
  5. data _null_;
  6.   call system(&opti);
  7. run;
  8. %fn:
复制代码

.....%mend


因为我做的是蒙特卡洛模拟,所以可能要等过夜,加了选项就会好很多.

另外,SAS如果强行关闭,SAS暂存文件夹(Work集)不清空,这两段批处理代码还没整合到宏里面:

rmdir /S /Q "C:\Users\lenovo\AppData\Local\Temp\SAS Temporary Files"
mkdir "C:\Users\lenovo\AppData\Local\Temp\SAS Temporary Files"


已有 1 人评分学术水平 热心指数 信用等级 收起 理由
davil2000 + 1 + 1 + 1 keep on

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

Bye SAS.
若有缘,能重聚。

使用道具

8
zhentao 发表于 2012-12-16 18:06:45 |只看作者 |坛友微信交流群
不错,呵呵。学习了。

使用道具

9
南海游客 发表于 2012-12-23 16:53:33 |只看作者 |坛友微信交流群
SAS也能使用DOS命令 赞

使用道具

10
wangyi1234567 发表于 2013-1-17 09:08:24 |只看作者 |坛友微信交流群
学习一下!

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 02:09