<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic EGRC 6.1 - How to copy attachments from Risk Event object in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/572850#M161678</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to copy attachments associated with risk events from EGRC 6.1 to a folder. There are about 300 risk events that i need to copy the attachments. How can I do this through SAS code?&lt;/P&gt;&lt;P&gt;My sample code (some code was obtained from the community)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
select t1.BUSINESS_OBJECT_RK into: rk saperated by '-' 
FROM SASOPRSK.ATTACHMENT_L t1, SASOPRSK.OP_RISK_EVENT_L t2, SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) AND t1.ATTACHMENT_TYPE_CD ne "LNK" and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' AND t3.AUX_RMG_DIM_1_RK = 10023);

select FILE_NM into: file saperated by '-'
FROM SASOPRSK.ATTACHMENT_L t1, SASOPRSK.OP_RISK_EVENT_L t2, SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) AND t1.ATTACHMENT_TYPE_CD ne "LNK" and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' AND t3.AUX_RMG_DIM_1_RK = 10023);
quit;

%macro attachment;
proc sql noprint;

select count(*) into: count
FROM SASOPRSK.ATTACHMENT_L t1, SASOPRSK.OP_RISK_EVENT_L t2, SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) AND t1.ATTACHMENT_TYPE_CD ne "LNK" and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' AND t3.AUX_RMG_DIM_1_RK = 10023);
quit;

%do i = 1 %to &amp;amp;count;
*filename out temp;
%let rk_l=%scan(%bquote(&amp;amp;rk), %bquote(&amp;amp;i) ,%str(-));
%let file_l=%scan(%bquote(&amp;amp;file), %bquote(&amp;amp;i) ,%str(-));

options dlcreatedir;
libname newdir "E:/anexos"; libname pasta "E:/anexos/&amp;amp;rk_l"; filename out "E:/anexos/&amp;amp;rk_l/&amp;amp;file_l";
libname newdir clear;
libname pasta clear;

proc http
method="get"
url="http://lqc6001sas05.unix.grupo.com:7980/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/op_risk_event/&amp;amp;rk_l/&amp;amp;file_l" 

webUserName="sasadm@saspw"
webPassword="****"
out=out;
run;
%end;
%mend;
%attachment;

&lt;/PRE&gt;&lt;P&gt;With this code I get the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTTP Status 404 The requested resource is not available&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jorge&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jul 2019 10:05:56 GMT</pubDate>
    <dc:creator>JorgeTavares</dc:creator>
    <dc:date>2019-07-12T10:05:56Z</dc:date>
    <item>
      <title>EGRC 6.1 - How to copy attachments from Risk Event object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/572850#M161678</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to copy attachments associated with risk events from EGRC 6.1 to a folder. There are about 300 risk events that i need to copy the attachments. How can I do this through SAS code?&lt;/P&gt;&lt;P&gt;My sample code (some code was obtained from the community)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
select t1.BUSINESS_OBJECT_RK into: rk saperated by '-' 
FROM SASOPRSK.ATTACHMENT_L t1, SASOPRSK.OP_RISK_EVENT_L t2, SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) AND t1.ATTACHMENT_TYPE_CD ne "LNK" and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' AND t3.AUX_RMG_DIM_1_RK = 10023);

select FILE_NM into: file saperated by '-'
FROM SASOPRSK.ATTACHMENT_L t1, SASOPRSK.OP_RISK_EVENT_L t2, SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) AND t1.ATTACHMENT_TYPE_CD ne "LNK" and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' AND t3.AUX_RMG_DIM_1_RK = 10023);
quit;

%macro attachment;
proc sql noprint;

select count(*) into: count
FROM SASOPRSK.ATTACHMENT_L t1, SASOPRSK.OP_RISK_EVENT_L t2, SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) AND t1.ATTACHMENT_TYPE_CD ne "LNK" and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' AND t3.AUX_RMG_DIM_1_RK = 10023);
quit;

%do i = 1 %to &amp;amp;count;
*filename out temp;
%let rk_l=%scan(%bquote(&amp;amp;rk), %bquote(&amp;amp;i) ,%str(-));
%let file_l=%scan(%bquote(&amp;amp;file), %bquote(&amp;amp;i) ,%str(-));

options dlcreatedir;
libname newdir "E:/anexos"; libname pasta "E:/anexos/&amp;amp;rk_l"; filename out "E:/anexos/&amp;amp;rk_l/&amp;amp;file_l";
libname newdir clear;
libname pasta clear;

proc http
method="get"
url="http://lqc6001sas05.unix.grupo.com:7980/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/op_risk_event/&amp;amp;rk_l/&amp;amp;file_l" 

webUserName="sasadm@saspw"
webPassword="****"
out=out;
run;
%end;
%mend;
%attachment;

&lt;/PRE&gt;&lt;P&gt;With this code I get the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTTP Status 404 The requested resource is not available&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jorge&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 10:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/572850#M161678</guid>
      <dc:creator>JorgeTavares</dc:creator>
      <dc:date>2019-07-12T10:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: EGRC 6.1 - How to copy attachments from Risk Event object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/572877#M161687</link>
      <description>&lt;P&gt;Please post code into a code box opened using the forum's {I} or "running man" icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not going to even attempt to read code as posted.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 17:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/572877#M161687</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-11T17:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: EGRC 6.1 - How to copy attachments from Risk Event object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/573027#M161739</link>
      <description>&lt;DIV class="frame"&gt;&lt;DIV class="page tlid-homepage homepage translate-text"&gt;&lt;DIV class="homepage-content-wrap"&gt;&lt;DIV class="tlid-source-target main-header small-font"&gt;&lt;DIV class="source-target-row"&gt;&lt;DIV class="tlid-results-container results-container"&gt;&lt;DIV class="tlid-result result-dict-wrapper"&gt;&lt;DIV class="result tlid-copy-target"&gt;&lt;DIV class="text-wrap tlid-copy-target"&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;DIV class="frame"&gt;&lt;DIV class="page tlid-homepage homepage translate-text"&gt;&lt;DIV class="homepage-content-wrap"&gt;&lt;DIV class="tlid-source-target main-header small-font"&gt;&lt;DIV class="source-target-row"&gt;&lt;DIV class="tlid-results-container results-container"&gt;&lt;DIV class="tlid-result result-dict-wrapper"&gt;&lt;DIV class="result tlid-copy-target"&gt;&lt;DIV class="text-wrap tlid-copy-target"&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;I was using IE11 and with this browser the toolbar did not appear.&lt;/SPAN&gt; &lt;SPAN&gt;I passed to the Chrome and the toolbar appeared with the "insert code" button.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 12 Jul 2019 10:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/573027#M161739</guid>
      <dc:creator>JorgeTavares</dc:creator>
      <dc:date>2019-07-12T10:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: EGRC 6.1 - How to copy attachments from Risk Event object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/573156#M161771</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138827"&gt;@JorgeTavares&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV class="frame"&gt;
&lt;DIV class="page tlid-homepage homepage translate-text"&gt;
&lt;DIV class="homepage-content-wrap"&gt;
&lt;DIV class="tlid-source-target main-header small-font"&gt;
&lt;DIV class="source-target-row"&gt;
&lt;DIV class="tlid-results-container results-container"&gt;
&lt;DIV class="tlid-result result-dict-wrapper"&gt;
&lt;DIV class="result tlid-copy-target"&gt;
&lt;DIV class="text-wrap tlid-copy-target"&gt;
&lt;DIV class="result-shield-container tlid-copy-target"&gt;
&lt;DIV class="frame"&gt;
&lt;DIV class="page tlid-homepage homepage translate-text"&gt;
&lt;DIV class="homepage-content-wrap"&gt;
&lt;DIV class="tlid-source-target main-header small-font"&gt;
&lt;DIV class="source-target-row"&gt;
&lt;DIV class="tlid-results-container results-container"&gt;
&lt;DIV class="tlid-result result-dict-wrapper"&gt;
&lt;DIV class="result tlid-copy-target"&gt;
&lt;DIV class="text-wrap tlid-copy-target"&gt;
&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;I was using IE11 and with this browser the toolbar did not appear.&lt;/SPAN&gt; &lt;SPAN&gt;I passed to the Chrome and the toolbar appeared with the "insert code" button.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="result-shield-container tlid-copy-target"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm using IE11 and don't have a problem with seeing the tool bar but who knows what local settings may have been inflicted on you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you get the connection to work with a hardcoded (no macro variables at all) before attempting the macro code?&lt;/P&gt;
&lt;P&gt;When testing macros you want to use the system options MPRINT and often SYMBOLGEN to see what actual code was created. It is a good idea when creating filenames or connection strings to use the dot at the end of the macro variables to make sure that the macro processor knows the difference between the end of your macro value and the "boiler plate" part of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;url="&lt;A href="http://lqc6001sas05.unix.grupo.com:7980/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/op_risk_event/&amp;amp;rk_l" target="_blank"&gt;http://lqc6001sas05.unix.grupo.com:7980/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/op_risk_event/&amp;amp;rk_l&lt;/A&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;FONT color="#ff00ff"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;/&amp;amp;file_l&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;FONT color="#ff00ff"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;" &lt;/P&gt;
&lt;P&gt;You really want to make sure that the rk_l and file_l variables don't have such things as leading spaces or / characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a little concerned about the use of %bquote on your RK variable as if you have some of the characters that %bquote protects in the values they are likely to be problems in the connection string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%bquote is&amp;nbsp;not needed in the %scan function for &amp;amp;I or the dash character. Example:&lt;/P&gt;
&lt;PRE&gt;%macro dummy;
%let rk=something separated-by-dashes when-I do not-the actual data;
%do i= 1 %to %sysfunc(countw(&amp;amp;rk.,-));
   %let rk_l = %scan(&amp;amp;rk,&amp;amp;i,-);
   %put RK_L is &amp;amp;rk_l.;
%end;
%mend;
%dummy;&lt;/PRE&gt;
&lt;P&gt;Just to make the code a little cleaner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am marginally concerned about the possibility of mismatched rk_l and file_l if values are missing for any of the records.&lt;/P&gt;
&lt;P&gt;And instead of making two (potentially quite time consuming) passes through the data I might be tempted to create the rk_l/file_ value&amp;nbsp;directly&amp;nbsp; such as :(obviously untested code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro dummy;
%let rk=something separated-by-dashes when-I do not-the actual data;
%do i= 1 %to %sysfunc(countw(&amp;amp;rk.,-));
   %let rk_l = %scan(&amp;amp;rk,&amp;amp;i,-);
   %put RK_L is &amp;amp;rk_l.;
%end;
%mend;
%dummy;

%macro attachment;

proc sql noprint;
select catx('/', strip(t1.BUSINESS_OBJECT_RK),strip(FILE_NM) ) into: list seperated by '-' 
FROM SASOPRSK.ATTACHMENT_L t1, 
     SASOPRSK.OP_RISK_EVENT_L t2, 
     SASOPRSK.DIM_POINT_L t3
WHERE (t1.SOURCE_SYSTEM_CD = t2.SOURCE_SYSTEM_CD 
      AND t1.BUSINESS_OBJECT_RK = t2.OP_RISK_EVENT_RK 
      AND t2.DIM_POINT_RK = t3.DIM_POINT_RK) 
      AND t1.ATTACHMENT_TYPE_CD ne "LNK" 
      and (t1.BUSINESS_OBJECT_NM = 'OP_RISK_EVENT' 
      AND t3.AUX_RMG_DIM_1_RK = 10023);
quit;

%let count=&amp;amp;sqlobs;
options dlcreatedir;

%do i=1 %to &amp;amp;count;
   %let List_l = %scan(%bquote(&amp;amp;list.),&amp;amp;i,-);
   libname newdir "E:/anexos"; 
   %let rk_l= %scan(&amp;amp;list_l,1,/);
   libname pasta "E:/anexos/&amp;amp;rk_l."; 
   filename out "E:/anexos/&amp;amp;list_l.";
   libname newdir clear;
   libname pasta clear;

   proc http
   method="get"
   url="http://lqc6001sas05.unix.grupo.com:7980/SASContentServer/repository/default/sasdav/Products/SASEnterpriseGRC/EnterpriseGRCMidTier6.1/Content/op_risk_event/&amp;amp;list_l." 

   webUserName="sasadm@saspw"
   webPassword="****"
   out=out;
   run;
%end;
%mend;
%attachment;
&lt;/PRE&gt;
&lt;P&gt;The catx function will create strings like rkvalue/listvalue. Strip function makes sure you don't have leading or trailing spaces.&lt;/P&gt;
&lt;P&gt;The macro variable &amp;amp;sqlobs contains the number of records resulting from the last proc sql select so no need to make a separate call just to count records. Or use the %sysfunc(countw()) approach shown in the dummy macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm wonder why create libnames just to clear them though. Perhaps you meant the CLEAR statements to go AFTER the proc http??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;404 errors often arise from incorrect paths so the actual content of your URL string is suspect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 16:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/EGRC-6-1-How-to-copy-attachments-from-Risk-Event-object/m-p/573156#M161771</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-12T16:33:20Z</dc:date>
    </item>
  </channel>
</rss>

