How to copy a .txt file from one host to another host through sas code without any change in the .txt file's format ?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

How to copy a .txt file from one host to another host through sas code without any change in the .txt file's format ?

here i am trying to copy a .txt file from one server to another  ftp server.But when I copy the file, I am getting the records in each  new line.But i want the records to be in the same line upto the line size of 1024 as they were in the original file.
I have attached the original(before_copy.txt) and copied file(after_copy.txt),which is same before_copy.txt after getting copied to ftp site.I have renamed it for your reference.

the code which i have used to copy the file is as follows:-

filename indir '/Shared/ABC/';
  
filename outdir ftp dir host='****'
         user='***' pass="***" ;

data _null_;

   infile indir(before_copy.txt)  lrecl=1024 ;
   input;
   file outdir(before_copy.txt)  lrecl=1024 ;
   put _infile_;
run;

Kinly let me know which option i need to use to copy the file as it was in the original one.

Attachment
Attachment

Accepted Solutions
Solution
‎06-27-2014 01:52 AM
Super User
Posts: 6,941

Re: How to copy a .txt file from one host to another host through sas code without any change in the .txt file's format ?

The files look to be in UNIX format (no CR/LF, only LF as line separator). But before_copy has 2 '0D'x characters, which are considered unwanted artifacts in UNIX text files and get stripped out by the FTP engine(s), most probably not SAS. You also have one empty line (2 '0A'x in succession) where SAS probably skips the line (missover default option).

Bottom line: if you need an _exact_ copy, use command line ftp/sftp and specify binary mode.

Or try the recfm=n option in SAS.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎06-27-2014 01:52 AM
Super User
Posts: 6,941

Re: How to copy a .txt file from one host to another host through sas code without any change in the .txt file's format ?

The files look to be in UNIX format (no CR/LF, only LF as line separator). But before_copy has 2 '0D'x characters, which are considered unwanted artifacts in UNIX text files and get stripped out by the FTP engine(s), most probably not SAS. You also have one empty line (2 '0A'x in succession) where SAS probably skips the line (missover default option).

Bottom line: if you need an _exact_ copy, use command line ftp/sftp and specify binary mode.

Or try the recfm=n option in SAS.

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

Re: How to copy a .txt file from one host to another host through sas code without any change in the .txt file's format ?

Hi from sas we can COPY, PASTE, CUT and DELETE the raw datafiles using X - Statement

Ex:-  X 'COPY "Path exist folder\test.txt" "Defined folder\out.txt"';

         X MOVE "Path exist folder\test.txt" "Defined folder\out.txt"';

SAS Super FREQ
Posts: 683

Re: How to copy a .txt file from one host to another host through sas code without any change in the .txt file's format ?

have a look at this blog entry Copy a file using a SAS program: another method - The SAS Dummy by Chris Hemedinger

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 981 views
  • 6 likes
  • 4 in conversation