BookmarkSubscribeRSS Feed
SAS_INFO
Quartz | Level 8

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

18 REPLIES 18
Reeza
Super User

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? 

SAS_INFO
Quartz | Level 8
I have checked without macros, but its not moving the file
SAS_INFO
Quartz | Level 8
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
Reeza
Super User

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

 

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

SAS_INFO
Quartz | Level 8
I haven't tried in command line and how to check CXCD is enabled
Jagadishkatam
Amethyst | Level 16

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
SAS_INFO
Quartz | Level 8
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
Jagadishkatam
Amethyst | Level 16
could you please try with mv rather than move
Thanks,
Jag
SAS_INFO
Quartz | Level 8
Wolaa,, it worked, with MV
Tom
Super User Tom
Super User

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.
SAS_INFO
Quartz | Level 8
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
Reeza
Super User

@SAS_INFO 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;

 

 

SAS_INFO
Quartz | Level 8
Sure, Reeza

Apologies
SAS_INFO
Quartz | Level 8

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

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
  • 18 replies
  • 3976 views
  • 5 likes
  • 5 in conversation