LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (August 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 13 Aug 2004 11:20:58 -0400
Reply-To:   "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:   Re: call execute long file names

Richard A. DeVenezia wrote: > Andre wrote: >> Hi, >> >> I'm trying to copy multiple files >> from one area to a second in Windows XP using SAS V8. >> >> If I had only one file to transfer I would simply write >> >> x "&copy ""&inpath"" ""&outpath"""; >> where &copy is copy >> inpath is c:\program files\from\test.sas >> and outpath is c:\program files\to\test.sas >> >> However now I'm trying to imitate this syntax through >> a call system statement and I'm having some problems. >> It was easy when I was testing using paths with no blanks >> but now this proves a little bit more complicated. >> >> I have a dataset (file_to_copy) containing >> 2 variables filefrom and fileto >> filefrom fileto >> c:\program files\from\test1.sas c:\program files\to\test1.sas >> c:\program files\from\test2.sas c:\program files\to\test2.sas >> c:\program files\from\test3.sas c:\program files\to\test3.sas >> c:\program files\from\test4.sas c:\program files\to\test4.sas >> >> Could someone fill in the blank in the code below to achive this? >> >> data _null_; >> set file_to_copy; >> command = "&copy " || ???? ; >> call system(command); >> run; >> >> Many thanks >> >> Andre > > You need to double quote the filename if the filename contains > embedded spaces (and it doesn't hurt if there are none.) The QUOTE() > function is handy for double quoting. If the filename itself > contains a double quote you have a little more to contend with. You > have to know how the OS escapes an embedded double quote. Windows > (Explorer anyway) disallows a double quote in a filename, so on that > platform I guess you don't have to worry about it. > > ----- > %let copy = COPY; > > options noxwait xmin noxsync; > > x dir/b c:\ > "c:\temp\a b"; > > data files; > src = 'c:\temp\a b'; > dst = 'c:\temp\a b c'; > run; > > data _null_; > set files; > command = "&COPY " || quote(src) || " " || quote(dst); > put command=; > call system (command); > run; > > data _null_; > do until (e1); > infile 'c:\temp\a b' end=e1; > input; > put _infile_; > end; > > put; > > do until (e2); > infile 'c:\temp\a b c' end=e2; > input; > put _infile_; > end; > > stop; > run; > -----

Andre replied in private mail that he got a NOTE: Invalid argument to function SYSTEM at line 14751 column 8.

I confirm that this does occur in version 8 but not in version 9 where I tested. The SYSTEM() function in version 8 also complains about an invalid argument.

Thus for version 8 a new tack is taken. Dynamically assign a filename pipe to execute the command when the fileref is opened.

---------- %let copy = COPY;

options noxwait xmin noxsync;

x del "c:\temp\a b"; x del "c:\temp\a b c"; x dir/b c:\ > "c:\temp\a b";

data files; src = 'c:\temp\a b'; dst = 'c:\temp\a b c'; run;

data _null_; set files; command = "&COPY " || quote(src) || " " || quote(dst); put command=;

* causes note in V8; * call system (command);

* causes note in V8; * rc = system (quote(command));

* assign command to temporary fileref (as a pipe) and execute command * by opening the fileref;

length fileref $8; fileref=" "; * fileref is blank going in and will contain a system assigned fileref upon return; rc = filename (fileref, command, "PIPE"); if rc = 0 then do; fid = fopen (fileref,'S'); if fid then do; fid = close (fid); end; else do; msg = sysmsg(); put msg=; end; end; * deassign the fileref; rc = filename (fileref); run;

data _null_; do until (e1); infile 'c:\temp\a b' end=e1; input; put _infile_; end;

put;

do until (e2); infile 'c:\temp\a b c' end=e2; input; put _infile_; end;

stop; run; ----------

-- Richard A. DeVenezia Done being productive? Try tetris. http://www.devenezia.com/downloads/sas/af?topic=27


Back to: Top of message | Previous page | Main SAS-L page