BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Azeem112
Quartz | Level 8

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Azeem112
Quartz | Level 8

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

13 REPLIES 13
andreas_lds
Jade | Level 19

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.

Azeem112
Quartz | Level 8
I want to place my files on the directory or server. I can access the server and get my files from server
Shmuel
Garnet | Level 18

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.

Kurt_Bremser
Super User

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

Kurt_Bremser
Super User

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.

Azeem112
Quartz | Level 8
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.
Kurt_Bremser
Super User

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
Quartz | Level 8
I want to create path using my code.
Azeem112
Quartz | Level 8
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.
Shmuel
Garnet | Level 18

Thank you @Kurt_Bremser

 

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

Azeem112
Quartz | Level 8

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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