BookmarkSubscribeRSS Feed
vicky07
Quartz | Level 8

Hello,

I am using SAS EG and I'm trying to use X command to create a folder and move files using mv command. The create directory stop is working fine however, the file move step is not working.  I cant figure out what is wrong with my syntax.

I am not getting any error and the files are not moving. Any help is appreciated.

 

Below is my code:

 

%let curr = %str(/Client/Market Ops/%sysfunc(today(),yymmddp9.)/);

%macro a1;

%let tm= %sysfunc(time(),time8.0) ;
%let archive = archive_%scan(&tm.,3,:);

 

/* create directory */

x "mkdir ""/&curr/&archive.""";

 

/* move files from current directory to archive*/
x "mv ""&curr/*.*"" ""&curr/&archive.""";
%mend;
%a1;

2 REPLIES 2
Tom
Super User Tom
Super User

How can you generated a date string with punctuation that is only 9 characters long?  You should need 10,  4 for the year, 2 for the month, 2 for the day and 2 for punctuation.

%let curr = /Client/Market Ops/%sysfunc(today(),yymmddp10.)/ ;

You have extra slashes in there. The %LET is generating a string with a slash at the beginning and at the end into the macro variable &CURR.  But then later when you use the value you add an extra one in front of it and after it. 

x "mkdir ""&curr.&archive."" ";
x "mv ""&curr.*.*"" ""&curr.&archive."" ";

 

Two additional points.

1) I find it is usually easier to let the QUOTE() function figure out when you need to double embedded quotes.

x %sysfunc(quote(mkdir "&curr.&archive."));

2) I find using a PIPE to run commands works much better than just the X (or SYSTEM) command.  That way you can actually capture any messages the operating system is sending you.

data _null_;
  infile %sysfunc(quote(mv "&curr.*.*" "&curr.&archive.")) pipe ;
  input;
  put _infile_;
run;

 

Kurt_Bremser
Super User

The string inside the quotes is expanded by the UNIX shell, creating a single object (because of the quotes) which does not exist.

You need to move every file in a single mv.

Let this be an object lesson why you must not have blanks in filenames, period.

Blanks are the natural separator of items on the commandline and must therefore not be used in object names, or they cause problems like this.

See Maxim 44.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 414 views
  • 0 likes
  • 3 in conversation