DATA Step, Macro, Functions and more

Copying output .CSV file to Shared Drive

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Copying output .CSV file to Shared Drive

Can anyone help me in providing a code for copying output(.CSV) file into Shared drive through Base sas code?

 

Thanks,

Abhi


Accepted Solutions
Solution
‎11-28-2016 02:24 AM
Contributor
Posts: 33

Re: Copying output .CSV file to Shared Drive

[ Edited ]
filename _bcin1 "C:\PATH\FILE.csv" recfm=n /* RECFM=N needed for a binary copy */;
filename _bcout1 "C:\NEWPATH\FILE.csv" recfm=n;

data _null_;
length msg $ 384;
rc=fcopy('_bcin1', '_bcout1');
if rc=0 then
put 'Copied _bcin1 to _bcout1.';
else do;
msg=sysmsg();
put rc= msg=;
end;
run;

filename _bcin1 clear;
filename _bcout1 clear;

 

View solution in original post


All Replies
Solution
‎11-28-2016 02:24 AM
Contributor
Posts: 33

Re: Copying output .CSV file to Shared Drive

[ Edited ]
filename _bcin1 "C:\PATH\FILE.csv" recfm=n /* RECFM=N needed for a binary copy */;
filename _bcout1 "C:\NEWPATH\FILE.csv" recfm=n;

data _null_;
length msg $ 384;
rc=fcopy('_bcin1', '_bcout1');
if rc=0 then
put 'Copied _bcin1 to _bcout1.';
else do;
msg=sysmsg();
put rc= msg=;
end;
run;

filename _bcin1 clear;
filename _bcout1 clear;

 

Contributor
Posts: 31

Re: Copying output .CSV file to Shared Drive

Hi,

The code is not copying the file from SAS server to the local system(shared drive). Could you please brief me about the code and help me to fix the issue.

Contributor
Posts: 31

Re: Copying output .CSV file to Shared Drive

Hi,
could you please help me in explaining me this code, as I am new to SAS I would like to understand what it does. Meanwhile, I tried your code. It doesn't work. Please help.
Super User
Posts: 6,928

Re: Copying output .CSV file to Shared Drive

If you have access to the network share from your SAS server (mounted directory), just create the file there.

If that is not the case, you will have to use another tool (ie SFTP) to copy the newly created file to that location. This requires a SSH server daemon on the file share server or on a machine that has the directory mounted. And of course XCMD enabled, if you want to do it from SAS.

And to make it work seamlessly, you need to configure your SSH connection for public/private key authentication.

 

For further help, provide information

- operating system(s) of all machines/hosts involved

- is the network share available on your SAS server

- is SSH present on a host that has the network share mounted (or on the file server itself)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

Re: Copying output .CSV file to Shared Drive

I am clear now. Thank you so much

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Super User
Posts: 7,392

Re: Copying output .CSV file to Shared Drive

You would use your operating system commands to copy files.  What these are depends on the OS SAS is installed on, and wether you have access to the paths and wether source and location are the same OS.

If it was Windows then you could do:

x 'copy "c:\originalfile.csv" "c:\newpath\originalfile.csv"';

 

Why not just copy an dpaste it using Win Explorer.  You will of course have a procesdure for importing data and validating it, as part of the process you would save/copy the file.  Why does it need to be done in SAS?

Contributor
Posts: 31

Re: Copying output .CSV file to Shared Drive

Hi,
In SAS we have the logic written, that will generate an output file which
will be in .CSV format. We use to copy the file in a shared drive, then a
job runs.. as of now we are doing this manually. I neee to do this through
SAS code.. each and every time copying a file manually to a shared drive is
tiresome . And we do all these in SAS server.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Super User
Posts: 7,392

Re: Copying output .CSV file to Shared Drive

So why do you not just directyl write the file to the shared area:

proc export outtfile="\\somewhere\shared\your_xl.xlsx"...

Contributor
Posts: 31

Re: Copying output .CSV file to Shared Drive

Proc export will work only within the sas server.
but to transfer those files we may use some unix commands. That's the re reason I am thinking how to do this within SAS code
Super User
Super User
Posts: 7,392

Re: Copying output .CSV file to Shared Drive

You haven't stated what the problem is.  You have some data in SAS, and you want to create a CSV file somewhere.  You do not need to copy this file, you just put the location of the final file in the proc export statement as I showed:

proc export outtfile="\\somewhere\shared\your_csv.csv"...

 

This wil work to any network area you have access to, and doesn't require anything further as CSV=Comma Separated Variable file which is plain text.  If of course you don't have access to the network area in your SAS session, then there is no method of getting the file to that location via SAS.  If you are having problems with network locations, then speak with your IT group about aquiring the correct permissions.

☑ This topic is SOLVED.

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

Discussion stats
  • 10 replies
  • 389 views
  • 2 likes
  • 4 in conversation