Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macros SAS,处理宏输出_Macros_Dataset_Sas_Output - Fatal编程技术网

Macros SAS,处理宏输出

Macros SAS,处理宏输出,macros,dataset,sas,output,Macros,Dataset,Sas,Output,为了列出文件夹中的所有文件,我从SAS网站获取了一个SAS宏。 这是完整的参考: 这就是代码: %macro drive(dir,ext); %let filrf=mydir;

为了列出文件夹中的所有文件,我从SAS网站获取了一个SAS宏。 这是完整的参考:

这就是代码:

%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); 产出

然后从数据步骤内部调用宏,就可以使用结果了。实际上,您最好只在一个数据步骤中运行所有这些,而不必为宏操心——它比只作为宏所需要的更复杂;在更短的数据步骤中