You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询:批量查看SAS服务器.sas程序修改时间及便捷备份方法

SAS服务器上.sas程序的批量日期查看与备份方案

1. 批量查看所有.sas程序的最后修改日期

dictionary.tables仅针对SAS库内的数据集,要获取外部.sas程序的修改日期,推荐两种实用方法:

方法一:系统命令+SAS导入

通过SAS调用系统命令遍历文件夹并导出文件信息,再读入SAS处理:

  • Windows环境:
filename dircmd pipe 'dir "Servers\SASApp\Home\*.sas" /s /tc /b';

data sas_files;
  infile dircmd truncover;
  input file_path $256.;
  modify_time = scan(pipe("for %f in ("||file_path||") do @echo %~tf"),2,' ');
run;

proc print data=sas_files;
  title "所有.sas程序的修改日期";
run;
  • Linux/Unix环境:
filename dircmd pipe 'find /Servers/SASApp/Home -name "*.sas" -printf "%p|%TY-%Tm-%Td %TH:%TM\n"';

data sas_files;
  infile dircmd delimiter='|' truncover;
  input file_path $256. modify_time :datetime20.;
  format modify_time datetime20.;
run;

proc print data=sas_files;
  title "所有.sas程序的修改日期";
run;

方法二:SAS函数递归遍历

通过filename关联文件夹,结合fopen、finfo函数递归读取文件属性:

%macro list_sas_files(root_path);
  filename dir "&root_path.";
  data sas_files;
    length file_path $256 modify_time $20;
    dir_id = dopen('dir');
    if dir_id > 0 then do;
      do i = 1 to dnum(dir_id);
        entry_name = dread(dir_id,i);
        entry_path = catx('\',"&root_path.",entry_name);
        if dopen(cats('dir_',i)) > 0 then do;
          %list_sas_files(&entry_path.)
        end;
        else if lowcase(scan(entry_name,-1,'.')) = 'sas' then do;
          file_id = fopen(entry_path);
          if file_id > 0 then do;
            modify_time = finfo(file_id,'Last Modified');
            output;
            rc = fclose(file_id);
          end;
        end;
      end;
      rc = dclose(dir_id);
    end;
  run;
%mend;

%list_sas_files(Servers\SASApp\Home)

proc print data=sas_files;
  var file_path modify_time;
  title "所有.sas程序的修改日期";
run;

2. 便捷备份.sas程序

直接调用系统备份命令是最高效的方式:

Windows环境(支持增量备份)

/* 完整备份所有.sas文件 */
x 'robocopy "Servers\SASApp\Home" "D:\SAS_Backup" *.sas /E';

/* 仅备份修改过的文件(增量备份) */
x 'robocopy "Servers\SASApp\Home" "D:\SAS_Backup" *.sas /E /XO';

Linux/Unix环境

/* 打包为压缩文件备份 */
x 'tar -czf /sas_backup/sas_programs.tar.gz /Servers/SASApp/Home/*.sas --recursive';

/* 直接复制到备份目录 */
x 'cp -r /Servers/SASApp/Home/*.sas /sas_backup/';

可将上述备份命令封装成SAS宏,结合SAS调度工具实现定时自动备份。

内容的提问来源于stack exchange,提问作者thedavidbaird

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 13:32:18