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

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

 

Thanks,

Abhi

1 ACCEPTED SOLUTION

Accepted Solutions
TheShark
Obsidian | Level 7
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

10 REPLIES 10
TheShark
Obsidian | Level 7
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;

 

Abhi1212
Obsidian | Level 7

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.

Abhi1212
Obsidian | Level 7
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.
Kurt_Bremser
Super User

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)

Abhi1212
Obsidian | Level 7
I am clear now. Thank you so much

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

Abhi1212
Obsidian | Level 7
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. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

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

Abhi1212
Obsidian | Level 7
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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

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
  • 10 replies
  • 3762 views
  • 2 likes
  • 4 in conversation