DATA Step, Macro, Functions and more

How to save attachments in a physical location of an object in SAS

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

How to save attachments in a physical location of an object in SAS

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.

 


Accepted Solutions
Solution
‎02-02-2018 05:59 AM
Contributor
Posts: 29

Re: How to save attachments in a physical location of an object in SAS

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.

 

View solution in original post


All Replies
Valued Guide
Posts: 580

Re: How to save attachments in a physical location of an object in SAS

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.

Contributor
Posts: 29

Re: How to save attachments in a physical location of an object in SAS

Posted in reply to andreas_lds
I want to place my files on the directory or server. I can access the server and get my files from server
Trusted Advisor
Posts: 1,837

Re: How to save attachments in a physical location of an object in SAS

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.

Super User
Posts: 10,280

Re: How to save attachments in a physical location of an object in SAS

[ Edited ]

@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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 10,280

Re: How to save attachments in a physical location of an object in SAS

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 29

Re: How to save attachments in a physical location of an object in SAS

Posted in reply to KurtBremser
I can't do this because in my drive there is not any folder of name as object_rk and this code is giving me HTTP client error because physical path didn't exist.
Super User
Posts: 10,280

Re: How to save attachments in a physical location of an object in SAS

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 29

Re: How to save attachments in a physical location of an object in SAS

Posted in reply to KurtBremser
I want to create path using my code.
Super User
Posts: 10,280

Re: How to save attachments in a physical location of an object in SAS


Azeem112 wrote:
I want to create path using my code.

Look at the fcreate() data step function.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 29

Re: How to save attachments in a physical location of an object in SAS

Posted in reply to KurtBremser
I managed to create my path using code but I'm still having issues as there is not any file having same name as file_nm. so proc HTTP gives error because he can't place incoming data from SAS content server to a file.
Super User
Posts: 10,280

Re: How to save attachments in a physical location of an object in SAS

Please post the complete code and log of the proc http step and the filename statement preceding it.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Trusted Advisor
Posts: 1,837

Re: How to save attachments in a physical location of an object in SAS

Posted in reply to KurtBremser

Thank you @KurtBremser

 

BTW the function is dcreate() - to create a directry/subdirectory (not fcreate);

Solution
‎02-02-2018 05:59 AM
Contributor
Posts: 29

Re: How to save attachments in a physical location of an object in SAS

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.

 
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 284 views
  • 2 likes
  • 4 in conversation