Can anyone help me in providing a code for copying output(.CSV) file into Shared drive through Base sas code?
Thanks,
Abhi
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;
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;
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.
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)
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?
So why do you not just directyl write the file to the shared area:
proc export outtfile="\\somewhere\shared\your_xl.xlsx"...
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.
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.