Hi I want to get all attachments from SAS content server of solution EGRC 6.1 policy object and want to save it in a physical location on my server.
This is what I'm doing now.
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;
I'm saving my attachment files in temp file but I want to save in a physical location as "C drive" inside a folder named as their rk of my object with proper extension as file.doc, file.xls or file.jpg etc.
example
obj_nm rk file_nm
POLICY_INST 12 file.xls
POLICY_INST 13 file.doc
POLICY_INST 14 file.gif
I want to put those files as
C:/12/file.xls
C:/13/file.doc
C:/14/file.gif
Kindly tell me how can I save my files from SAS content server to a physical location of my server with proper extension.
This is my code
%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(-));
options dlcreatedir;
libname newdir "C:/attachments/&rk_l";
filename out "C:/attachments/&rk_l/&file_l";
%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;
Thanks for help, this code is working fine.
You are, most likely, using sas on a server. That server is not able to access your local drives. You could try an UNC-path if the server sees your computer that should work. But using a network-share is recommended.
You wrote: "I'm saving my attachment files in temp file ..." -
I don't see any assignment to a temp file in your code.
Can you show where is that assignment - usually a FILENAME statement ?
Just change the assignment to physical path and name you prefer.
If the program runs in the server - assign physical path in the server.
@Shmuel it's there:
%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(-));
TBH, it also took me some time to find it.
If you put files on a server like this:
C:/12/file.xls C:/13/file.doc C:/14/file.gif
where I am the admin, I'd come after you with a LART.
But it wouldn't happen, of course, because you wouldn't have write permission in the root directory anyway.
Why don't you simply make your filename dynamic:
%do i = 1 %to &count;
%let rk_l=%scan(%bquote(&rk), %bquote(&i) ,%str(-));
%let file_l=%scan(%bquote(&file), %bquote(&i) ,%str(-));
filename out "E:\somewhere_you_may_write_to\&rk_l.\&file_l.";
You might also need to take care of instances where the path &rk_l does not yet exist.
If you want to write files to a server, you must of course make sure that the path exists and is writable by you. That's a very obvious given.
To create such a path, you must talk with the server admin.
@Azeem112 wrote:
I want to create path using my code.
Look at the fcreate() data step function.
Please post the complete code and log of the proc http step and the filename statement preceding it.
Thank you @Kurt_Bremser.
BTW the function is dcreate() - to create a directry/subdirectory (not fcreate);
This is my code
%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(-));
options dlcreatedir;
libname newdir "C:/attachments/&rk_l";
filename out "C:/attachments/&rk_l/&file_l";
%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;
Thanks for help, this code is working fine.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.