楼主: 3qsir
2673 6

About : Macro to Rename Files [推广有奖]

  • 2关注
  • 1粉丝

副教授

52%

还不是VIP/贵宾

-

威望
0
论坛币
13606 个
通用积分
27.0809
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
71836 点
帖子
367
精华
0
在线时间
931 小时
注册时间
2011-5-18
最后登录
2021-3-6

楼主
3qsir 发表于 2014-3-14 12:07:08 |AI写论文
10论坛币

My question:

I have many excel files onc:\temp\p001.xls…..p100.xls

I want to rename p001.xls…..p100.xls to q001.xls…..q100.xls

ie. (rename q001.xls= p001.xls ….. q100.xls=p100.xls)

------------------------------------------------------------------------

I search this paper “Useful SAS Macros andRoutines” from SAS Global Forum 2007 by Flora and Miguel

(paper 059-2007) tofind their SAS codes only mention about

“Macro to Open(Delete) Excel file” onpage 1, None “Macro to Rename Excel file”,

Sir mat  you help me to write a code follow theirs,THS!

关键词:rename About Files Macro Bout question search files excel about

本帖被以下文库推荐

沙发
3qsir 发表于 2014-3-14 22:55:40
Hints to “Macro to Rename Excel file”
Sir can  you  write a similar with code follow below code  ,THS!
----------------------------------------------------------
/*macro to open Excel and excel file*/
%Macro OpenXls(pfile);
OPTIONS NOXWAIT NOXSYNC MISSING='';
x"C:\Archiv~1\micros~2\Office10\execel.exe/&pFile..xls";
%sleep(2);
%MEND;
------------------------------------------------------
This codes almostly copy from this paper
“Useful SAS Macros and Routines” from SAS Global Forum 2007
by Flora and Miguel

%MACRO Sleep(&pSeconds);
  DATA_NULL_;
  vVar1=SLEEP(&pseconds);
RUN;
%MEND;

藤椅
可~乐 发表于 2014-3-15 20:05:03
  1. %macro rename(dir=);
  2. filename rename pipe "dir &dir.\*.xls /b";

  3. data _null_;
  4.         infile rename;
  5.         input name:$100.;
  6.                 old_name=name;
  7.                 substr(name,1,1)='q';
  8.                 call symputx("old_name"||left(_n_),old_name);
  9.                 call symputx("name"||left(_n_),name);
  10.                 call symputx("number",left(_n_));
  11. run;

  12. data _null_;
  13.         %do i=1 %to &number.;
  14.                 rc=rename("&dir.\&&old_name&i.","&dir.\&&name&i.","file");
  15.         %end;
  16. run;
  17. %mend;

  18. %rename(dir=D:\test);
复制代码

板凳
3qsir 发表于 2014-3-16 20:20:28
SIR : BUGS IN CODES

14         GOPTIONS ACCESSIBLE;
15         %macro rename(dir=);
16         
17         filename rename pipe "dir &dir.\*.xls /b";
18         
19         
20         data _null_;
21         
22                 infile rename;
23         
24                 input name:$100.;
25         
26                         old_name=name;
27         
28                         substr(name,1,1)='q';
29         
30                         call symputx("old_name"||left(_n_),old_name);
31         
32                         call symputx("name"||left(_n_),name);
33         
34                         call symputx("number",left(_n_));
35         
36         run;
37         
38         
39         data _null_;
40         
41                 %do i=1 %to &number.;
42         
43                         rc=rename("&dir.\&&old_name&i.","&dir.\&&name&i.","file");
44         
45                 %end;
46         
47         run;
48         
49         %mend;
50         
51         
52         %rename(dir=D:\test);
ERROR: Insufficient authorization to access PIPE.
ERROR: Error in the FILENAME statement.
ERROR: No logical assign for filename RENAME.
WARNING: Apparent symbolic reference NUMBER not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a
       numeric operand is required. The condition was: &number.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro RENAME will stop executing.
53         
54         GOPTIONS NOACCESSIBLE;
55         %LET _CLIENTTASKLABEL=;
56         %LET _CLIENTPROJECTPATH=;
57         %LET _CLIENTPROJECTNAME=;
58         %LET _SASPROGRAMFILE=;
59         
60         ;*';*";*/;quit;run;
                     ____
                     180
ERROR 180-322: Statement is not valid or it is used out of proper order.
61         ODS _ALL_ CLOSE;
62         
63         
64         QUIT; RUN;
65         

报纸
dogmamongo 发表于 2014-3-17 10:02:30
如果只是改原始档名
网路上搜寻 批次改名 就可以找到软件一次将档案一起改掉了

rename.rar
下载链接: https://bbs.pinggu.org/a-1508798.html

641.92 KB

批次改名软件

地板
可~乐 发表于 2014-3-17 20:59:51
3qsir 发表于 2014-3-16 20:20
SIR : BUGS IN CODES

14         GOPTIONS ACCESSIBLE;
14         GOPTIONS ACCESSIBLE;
15         %macro rename(dir=);
16         filename rename pipe "dir &dir.\*.xls /b";
17         
18         data _null_;
19                 infile rename;
20                 input name:$100.;
21                         old_name=name;
22                         substr(name,1,1)='q';
23                         call symputx("old_name"||left(_n_),old_name);
24                         call symputx("name"||left(_n_),name);
25                         call symputx("number",left(_n_));
26         run;
27         
28         data _null_;
29                 %do i=1 %to &number.;
30                         rc=rename("&dir.\&&old_name&i.","&dir.\&&name&i.","file");
31                 %end;
32         run;
33         %mend;
34         
35         %rename(dir=D:\test);

NOTE: 数值已转换为字符值,位置:(行:列)。
      35:224   35:44    35:99   
NOTE: INFILE RENAME 是:
      未命名的管道访问设备,
      PROCESS=dir D:\test\*.xls /b,RECFM=V,LRECL=256

NOTE: 从 INFILE RENAME 中读取了 3 条记录。
      最小记录长度是 8。
      最大记录长度是 8。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.14 秒
      CPU 时间          0.01 秒
      


NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.00 秒
      CPU 时间          0.00 秒


You can have a look:
http://support.sas.com/kb/16/109.html

7
3qsir 发表于 2014-3-17 21:44:18
Run your code in my sas 9.22 is still ERROR are same yesterday post in line 52:
I look you give me sas technique web, My ERROR look like with Note16109 , I maybe change my SAS/Connect default . but it (SAS Note16109) hard to read  for me
1. What's different between your sas and my sas e/d ?
------------------------------------------------
Usage Note 16109: ERROR: Insufficient Authorization to access PIPE produced when connecting to SAS/CONNECT Spawner programs

The following error may occur when attempting to remote submit X commands to a remote host running a SAS/CONNECT® Spawner:

   ERROR: Insufficient authorization to access PIPE.
   ERROR: Error in the FILENAME statement.

The following example may replicate this problem:

   filename x pipe 'env';
   data _null_;
   infile x;
   input;
   put _infile_;
   run;

By default, the UNIX SAS/CONNECT Spawner runs without a shell, which means that no processes that forks shell commands, such as X commands or SYSTASK will execute. To correct the problem, restart the Unix SAS/CONNECT Spawner with the -SHELL option.

For example:

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 10:23