如何在SAS中的对象的物理位置保存附件

时间:2018-02-01 07:58:21

标签: sas sas-macro

您好我想从解决方案EGRC 6.1策略对象的SAS内容服务器获取所有附件,并希望将其保存在我服务器上的物理位置。

这就是我现在正在做的事情。

proc sql noprint;
select BUSINESS_OBJECT_RK 
into: rk saperated by '-'
from sasoprsk.attachment_l
where BUSINESS_OBJECT_NM eq "POLICY_INST"
and   ATTACHMENT_TYPE_CD ne "LNK";

select FILE_NM 
into: file saperated by '-'
from sasoprsk.attachment_l
where BUSINESS_OBJECT_NM eq "POLICY_INST"
and   ATTACHMENT_TYPE_CD ne "LNK";

quit;


%macro attachment;

proc sql noprint;
select count(*) 
into: count
from sasoprsk.attachment_l
where BUSINESS_OBJECT_NM eq "POLICY_INST"
and   ATTACHMENT_TYPE_CD ne "LNK";
quit;

%do i = 1 %to &count;

filename out temp;

    %let rk_l=%scan(%bquote(&rk), %bquote(&i) ,%str(-));
    %let file_l=%scan(%bquote(&file), %bquote(&i) ,%str(-));

%put "file &file_l";
%put "http://sasbap.demo.sas.com/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/policy/&rk_l/&file_l"; 

proc http 
method="get"
url="http://sasbap.demo.sas.com/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/policy/&rk_l/&file_l"
webUserName="sas"
webPassword="Orion123"
out=out;
run;

%end;
%mend;  

%attachment;

我将我的附件文件保存在临时文件中,但是我希望将物理位置保存为名为rk of the object的文件夹中的“C盘”,并将其作为file.doc,file.xls或file进行正确扩展.jpg等。

example 
obj_nm        rk      file_nm
POLICY_INST   12      file.xls
POLICY_INST   13      file.doc
POLICY_INST   14      file.gif

我想把这些文件作为

C:/12/file.xls 
C:/13/file.doc
C:/14/file.gif 

请告诉我如何通过适当的扩展将我的文件从SAS内容服务器保存到服务器的物理位置。

1 个答案:

答案 0 :(得分:0)

只需在proc http来电之前添加以下内容:

%mf_mkdir(C:/&rk_l)
filename out "C:/&rk_l/&file_l";

mf_mkdir的源代码可在开源Boemska Macro Core library中找到,并转载如下:

/**
  @file
  @brief Creates a directory, including any intermediate directories
  @details Works on windows and unix environments via dcreate function.
Usage:

    %mf_mkdir(/some/path/name)


  @param dir relative or absolute pathname.  Unquoted.
  @version 9.2
  @copyright GNU GENERAL PUBLIC LICENSE v3
**/

%macro mf_mkdir(dir
)/*/STORE SOURCE*/;

  %local lastchar child parent;

  %let lastchar = %substr(&dir, %length(&dir));
  %if (%bquote(&lastchar) eq %str(:)) %then %do;
    /* Cannot create drive mappings */
    %return;
  %end;

  %if (%bquote(&lastchar)=%str(/)) or (%bquote(&lastchar)=%str(\)) %then %do;
    /* last char is a slash */
    %if (%length(&dir) eq 1) %then %do;
      /* one single slash - root location is assumed to exist */
      %return;
    %end;
    %else %do;
      /* strip last slash */
      %let dir = %substr(&dir, 1, %length(&dir)-1);
    %end;
  %end;

  %if (%sysfunc(fileexist(%bquote(&dir))) = 0) %then %do;
    /* directory does not exist so prepare to create */
    /* first get the childmost directory */
    %let child = %scan(&dir, -1, %str(/\:));

    /*
      If child name = path name then there are no parents to create. Else
      they must be recursively scanned.
    */

    %if (%length(&dir) gt %length(&child)) %then %do;
       %let parent = %substr(&dir, 1, %length(&dir)-%length(&child));
       %mf_mkdir(&parent);
    %end;

    /*
      Now create the directory.  Complain loudly of any errors.
    */

    %let dname = %sysfunc(dcreate(&child, &parent));
    %if (%bquote(&dname) eq ) %then %do;
       %put ERROR: could not create &parent\&child;
       %abort cancel;
    %end;
    %else %do;
       %put Directory created:  &dir;
    %end;
  %end;
  /* exit quietly if directory did exist.*/
%mend;