Macros SAS,处理宏输出
为了列出文件夹中的所有文件,我从SAS网站获取了一个SAS宏。 这是完整的参考: 这就是代码:Macros SAS,处理宏输出,macros,dataset,sas,output,Macros,Dataset,Sas,Output,为了列出文件夹中的所有文件,我从SAS网站获取了一个SAS宏。 这是完整的参考: 这就是代码: %macro drive(dir,ext); %let filrf=mydir;
%macro drive(dir,ext);
%let filrf=mydir;
/* Assigns the fileref of mydir to the directory and opens the directory */
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
/* Returns the number of members in the directory */
%let memcnt=%sysfunc(dnum(&did));
/* Loops through entire directory */
%do i = 1 %to &memcnt;
/* Returns the extension from each file */
%let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.);
/* Checks to see if file contains an extension */
%if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do;
/* Checks to see if the extension matches the parameter value */
/* If condition is true prints the full name to the log */
%if (%superq(ext) ne and %qupcase(&name) = %qupcase(&ext)) or
(%superq(ext) = and %superq(name) ne) %then %do;
%put %qsysfunc(dread(&did,&i));
%end;
%end;
%end;
/* Closes the directory */
%let rc=%sysfunc(dclose(&did));
%mend drive;
/* First parameter is the directory of where your files are stored. */
/* Second parameter is the extension you are looking for. */
/* Leave 2nd paramater blank if you want a list of all the files. */
%drive(c:\,sas)
这个宏(显然)工作正常,问题是它会在日志中返回结果。
我需要将这些结果放入SAS数据集中,以便安排其他操作。
我怎么做
提前感谢。首先,如果你能制作一个管道,你可以:
filename dirlist pipe "dir /b c:\*.sas";
data myfiles;
infile dirlist lrecl=512 truncover;
input
@1 fullname $512.;
filename = scan(fullname,-1,'\');
run;
如果由于系统限制,确实需要使用该宏,则不能直接从该宏获取输出,因为它除了打印到日志之外,什么都不做。您需要做以下两件事之一:
- 使用PROC print将日志重定向到一个文件,然后可以解析该文件
- 更改实际执行某些操作的代码行<代码>%put%qsysfunc(恐惧(&did,&i))代码>如果您将此更改为 filename=dread(&did,&i); 产出