DATA Step, Macro, Functions and more

Moving text files

Reply
Contributor
Posts: 63

Moving text files

Hi ,

 

I would like to move .txt files from one folder to another .

 

The txt files are like ab001.D170605.EDLY.txt

 

the following code is not working

%put x mv "&fpath/AB001.D&tdate..EDLY.TXT" &apath.;

x mv "&fpath/ET001.D&tdate..EDLY.TXT" &apath.;

 

 

where fpath = source location

apath=destination location

Super User
Posts: 19,772

Re: Moving text files

Posted in reply to arunasaran

Steps to debug this:

 

1. Does it work in command line 

2. Does it work without macros 

3. Does it work with basic skeleton macro

4. What does not work mean? 

Contributor
Posts: 63

Re: Moving text files

I have checked without macros, but its not moving the file
Contributor
Posts: 63

Re: Moving text files

Posted in reply to arunasaran
also tried this.

x "move "/data/DEVELOPMENT/LANDING/IN_FILES/ET001.D170605.EDLY.TXT" "/data/DEVELOPMENT/LANDING/ARCHIVED_IN"";

but the files are not moving and log is as follows:

GOPTIONS ACCESSIBLE;
24 x "move "/data/DEVELOPMENT/LANDING/IN_FILES/ET001.D170605.EDLY.TXT" "/data/DEVELOPMENT/LANDING/ARCHIVED_IN""
24 ! ;
25
26 GOPTIONS NOACCESSIBLE;
27 %LET _CLIENTTASKLABEL=;
28 %LET _CLIENTPROCESSFLOWNAME=;
29 %LET _CLIENTPROJECTPATH=;
30 %LET _CLIENTPROJECTNAME=;
31 %LET _SASPROGRAMFILE=;
32
33 ;*';*";*/;quit;run;
34 ODS _ALL_ CLOSE;
35
36
37 QUIT; RUN;
38
Super User
Posts: 19,772

Re: Moving text files

Posted in reply to arunasaran

So what was the answer to Q#1 and 2? 

 

Also, you're using EG, did you confirm that XMCD is enabled? 

Contributor
Posts: 63

Re: Moving text files

I haven't tried in command line and how to check CXCD is enabled
Trusted Advisor
Posts: 1,137

Re: Moving text files

Posted in reply to arunasaran

could you please try the below code without the quotes to the path mentioned within the x command after the mv command

 

x "mv /data/DEVELOPMENT/LANDING/IN_FILES/ET001.D170605.EDLY.TXT /data/DEVELOPMENT/LANDING/ARCHIVED_IN";
Thanks,
Jag
Contributor
Posts: 63

Re: Moving text files

Posted in reply to Jagadishkatam
Hi Jag,

Tried wat u said:

x "move /data/DEVELOPMENT/LANDING/IN_FILES/ET001.D170605.EDLY.TXT /data/DEVELOPMENT/LANDING/ARCHIVED_IN";

But nothing happened
Trusted Advisor
Posts: 1,137

Re: Moving text files

Posted in reply to arunasaran
could you please try with mv rather than move
Thanks,
Jag
Contributor
Posts: 63

Re: Moving text files

Posted in reply to Jagadishkatam
Wolaa,, it worked, with MV
Super User
Super User
Posts: 7,039

Re: Moving text files

Posted in reply to arunasaran

That is why I always call operating system commands using PIPE instead of using X or %SYSEXEC. When you call the command using an INFILE with PIPE engine you can read the response from the operating system.  If you had done that here you would have seem right away that the operating system did not understand the move command.

 

1    data _null_;
2      infile "move x y" pipe ;
3      input;
4      put _infile_;
5    run;

NOTE: The infile "move x y" is:
      Pipe command="move x y"

/bin/ksh: move: not found
NOTE: 1 record was read from the infile "move x y".
      The minimum record length was 25.
      The maximum record length was 25.
Contributor
Posts: 63

Re: Moving text files

Hi Reeza,

data _NULL_;
25 infile"move &fpath/ET002C.D170605.EDLY.TXT &apath" pipe;
26 input;
27 put _infile_;
28 run;

NOTE: The infile "move /data/DEVELOPMENT/LANDING/IN_FILES/ET002C.D170605.EDLY.TXT /data/DEVELOPMENT/LANDING/ARCHIVED_IN" is:
Pipe command="move /data/DEVELOPMENT/LANDING/IN_FILES/ET002C.D170605.EDLY.TXT /data/DEVELOPMENT/LANDING/ARCHIVED_IN"

/bin/bash: move: command not found
NOTE: 1 record was read from the infile "move /data/DEVELOPMENT/LANDING/IN_FILES/ET002C.D170605.EDLY.TXT
/data/DEVELOPMENT/LANDING/ARCHIVED_IN".
The minimum record length was 34.
The maximum record length was 34.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Super User
Posts: 19,772

Re: Moving text files

Posted in reply to arunasaran

@arunasaran Once tdate was defined it worked correctly for me. 

So define tdate. And post your code using the editor and take some time to format the question. We take the time to answer your questions but it's easier if you organize your process clearly from the beginning. 

 

%let tdate = %sysfunc(today(), yymmdd6.);
%put &tdate;

 

 

Contributor
Posts: 63

Re: Moving text files

Sure, Reeza

Apologies
Contributor
Posts: 63

Re: Moving text files

Posted in reply to Jagadishkatam

Hi Jag,

Tried the following and its working:

x "mv  /data/DEVELOPMENT/LANDING/IN_FILES/ET002A.D170605.EDLY.TXT  /data/DEVELOPMENT/LANDING/ARCHIVED_IN";

 

But I would like to use the macros for location and tdate of the file as:
x "mv  &fpath/ET002A.&tdate..EDLY.TXT  &apath";

 

where &tdate is todays date

Ask a Question
Discussion stats
  • 17 replies
  • 191 views
  • 3 likes
  • 4 in conversation