Re: Copy a file from one directory to another from a SAS program? #9

  • Permalink
  • submit to reddit
  • Email
  • Follow


Mary;

You got lots of suggestions for the use of the X statement.  Might I
suggest, instead, the use of the %sysExec statement.  This uses the
exact system command without the necessity of quoting the string like
you have to do with the X command.

%sysExec move c:\dir1\test.txt c:\dir2\ /y ;

Notice that we have no quotes.  Now, I often work with people who set up
directory structures that have embedded spaces in the folder names.  So
%sysExec allows me to code something like...

%sysExec move "\\server\the first dir\test.txt" "\\server\the second
dir\" /y ;

with the double-quotes that Windows wants.  I can very easily then move
to macro variables as my skills improve.

%let dir1 = \\server\the first dir ;
%let dir2 = C:\dir2 ;
....
%sysExec move "&dir1\test.txt" "dir2" /y ;

Now, if I'm already more advanced and am working in a macro which allows
use of the %if statement, I can use the system() function inside the
%sysFunc() function to enable error handling.  Something like...

%if ( %sysFunc( system( move "&dir1\test.txt" "dir2" /y ) ) gt 0 )
%then %do ;
        %put ERROR: text.txt was not moved from &dir1 to &dir2! ;
        %put ERROR- Processing was stopped for this macro. ;
        %return ;
%end ;

Of course, you will still want to use...

Options noXWait ;

Okay, I'll talk off my teacher hat!

Ed

Edward Heaton, Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1650 Research Boulevard, TB-286, Rockville, MD 20850-3195
Voice: (301) 610-4818                 Fax: (301) 294-2085
mailto:EdHeaton@Westat.com          http://www.Westat.com




-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Mary
Sent: Thursday, July 31, 2008 4:12 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Copy a file from one directory to another from a SAS
program?


Yes, that does work
X "move c:\dir1\test.txt c:\dir2\test.txt"

It is however, leaving open the DOS command window.   I tried:
X "exit";
and that did not work to close it.  Would anyone know how to close it?

-Mary
  ----- Original Message -----
  From: matt.pettis@thomsonreuters.com
  To: mlhoward@avalon.net ; SAS-L@LISTSERV.UGA.EDU
  Sent: Thursday, July 31, 2008 2:58 PM
  Subject: RE: Copy a file from one directory to another from a SAS
program?


  If you know the file names, you can do the 'X' command at some point
to
  execute a system command to move the file:

  X "move /path/to/original /path/to/dest";

  If you are on Windows (probably, since you are using .xls).
Otherwise,
  whatever command is native to your OS for moving files should work
  within your 'X' command.

  Matt

  -----Original Message-----
  From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
  Mary
  Sent: Thursday, July 31, 2008 2:05 PM
  To: SAS-L@LISTSERV.UGA.EDU
  Subject: Copy a file from one directory to another from a SAS program?

  Is there a way from SAS to copy a file from one directory to another?
  I am exporting 200+ sheets from an Excel 2007 workbook and there is
one
  sheet that I do not want to process like the others, so I'd like to
move
  it in my SAS program to another folder.

  -Mary
0
Reply EdHeaton (665) 8/1/2008 1:12:06 PM

See related articles to this posting


@Mary Thanks for raising that concern. I was trying to find a solution myself and 
you can solve your second problem by placing options NOXWAIT; in your program.
@Matt Thanks for your simple suggestion.
@Ed good but complicated for a simple task such the one Mary is asking for.
0
Reply simonsamir1 (1) 3/21/2013 12:50:31 PM
comp.soft-sys.sas 131468 articles. 29 followers. Post

1 Replies
283 Views

Similar Articles

[PageSpeed] 17


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Re: Copy a file from one directory to another from a SAS program?
If you know the file names, you can do the 'X' command at some point to execute a system command to move the file: X "move /path/to/original /path/to/dest"; If you are on Windows (probably, since you are using .xls). Otherwise, whatever command is native to your OS for moving files should work within your 'X' command. Matt -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mary Sent: Thursday, July 31, 2008 2:05 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Copy a file from one directory to another from a SAS program? Is the...

Re: Copy a file from one directory to another from a SAS program? #3
Check out the system options XWAIT|NOXWAIT and XSYNC and NOXSYNC from the online document. I think options noxwait might do it for you. HTH, -TJ On Thu, 31 Jul 2008 15:12:12 -0500, Mary <mlhoward@AVALON.NET> wrote: >Yes, that does work >X "move c:\dir1\test.txt c:\dir2\test.txt" > >It is however, leaving open the DOS command window. I tried: >X "exit"; >and that did not work to close it. Would anyone know how to close it? > >-Mary > ----- Original Message ----- > From: matt.pettis@thomsonreuters.com > To: mlhoward@avalon.ne...

Re: Copy a file from one directory to another from a SAS program? #7
Mary, You could, of course, simply not confront the dos window with something like: data _null_; systask command "move c:\dir1\test.txt c:\dir2"; run; Art --------- On Thu, 31 Jul 2008 15:12:12 -0500, Mary <mlhoward@AVALON.NET> wrote: >Yes, that does work >X "move c:\dir1\test.txt c:\dir2\test.txt" > >It is however, leaving open the DOS command window. I tried: >X "exit"; >and that did not work to close it. Would anyone know how to close it? > >-Mary > ----- Original Message ----- > From: matt.pettis@thomsonreuters.co...

Re: Copy a file from one directory to another from a SAS program? #6
It may be easier to not create the TXT file than to delete it later. put +6 'If objsheet.name <> "Sheet2" Then'; put +9 'WScript.echo i & " " & objsheet.name & " saving as TXT"'; put +9 'objSheet.SaveAs txtout & "\" & objSheet.name & ".txt", xlTextMSDOS'; put +9 'End If'; How do you determine the name of the unwanted sheet? On 7/31/08, Mary <mlhoward@avalon.net> wrote: > Yes, that does work > X "move c:\dir1\test.txt c:\dir2\test.txt&q...

Re: Copy a file from one directory to another from a SAS program? #2
Yes, that does work X "move c:\dir1\test.txt c:\dir2\test.txt" It is however, leaving open the DOS command window. I tried: X "exit"; and that did not work to close it. Would anyone know how to close it? -Mary ----- Original Message -----=20 From: matt.pettis@thomsonreuters.com=20 To: mlhoward@avalon.net ; SAS-L@LISTSERV.UGA.EDU=20 Sent: Thursday, July 31, 2008 2:58 PM Subject: RE: Copy a file from one directory to another from a SAS = program? If you know the file names, you can do the 'X' command at some point = to execute a system command to ...

Re: Copy a file from one directory to another from a SAS program? #8
I do want the sheet, but I have one sheet that has "patient level" = things and all the rest of the sheets are visit level, one sheet for = every patient in my patient level (theoretically, but I now can check = for that). So after I export all the sheets, I just copy off the one = sheet with the patient level stuff out of the directory, then I can use = the code worked out last week for Rodney Presley to read in all the = other sheets and put them all into one dataset. I an loading the data = from there to Oracle Express (we are going to get the standard version = soon), as two ...

Re: Copy a file from one directory to another from a SAS program? #5
try before the statement: =20 options noxwait; =20 shouldn't matter, but after the 'x' statement, you may want to turn the option back on (i personally never do) with: =20 options xwait; =20 hth, matt ________________________________ From: Mary [mailto:mlhoward@avalon.net]=20 Sent: Thursday, July 31, 2008 3:12 PM To: Pettis, Matthew (Prof II&RS); SAS-L@LISTSERV.UGA.EDU Subject: Re: Copy a file from one directory to another from a SAS program? Yes, that does work X "move c:\dir1\test.txt c:\dir2\test.txt" =20 It is however, leaving open the DOS command window. I ...

Re: Copy a file from one directory to another from a SAS program? #4
hi ... try this before using the X command ... options noxwait; "NOXWAIT specifies that the command processor automatically returns to the SAS session after the specified command is executed. You do not have to type EXIT." the online doc has a good explanation of XWAIT and XSYNC (sounds like EXTINCT, hmmm... DOS) -- Mike Zdeb U@Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475 > Yes, that does work > X "move c:\dir1\test.txt c:\dir2\test.txt" > > It is however, leaving open the DOS command win...

Copy a file from one directory to another from a SAS program?
Is there a way from SAS to copy a file from one directory to another? = I am exporting 200+ sheets from an Excel 2007 workbook and there is one = sheet that I do not want to process like the others, so I'd like to move = it in my SAS program to another folder. -Mary ...

Re: Copy from one directory in SAS to another,
The following code copy all files from c:\temp\v2 to c:\temp\v1, in the meantime, add a prefix 'xx' to all the new file names. filename allname pipe "dir/b c:\temp\v2\*.*"; options noxwait; data _null_; infile allname; input; file "c:\temp\renameall.bat"; put 'copy c:\temp\v2\' _infile_ ' c:\temp\v1\xx' _infile_; run; x "c:\temp\renameall.bat"; You can make it a macro very easily. On Mon, 22 Jan 2007 11:22:14 -0500, Jake Bee <johbee@GMAIL.COM> wrote: >Does anyone have any ideas on how to copy files from >one directory to ...

Re: Copy from one directory in SAS to another, #5
johbee@GMAIL.COM wrote: > >Does anyone have any ideas on how to copy files from >one directory to another, using SAS, in DOS, but >with renaming the new file in the new directory. >(The new file name has the first 6 bytes removed.) > >Thanks for any ideas! > >Jake I see that you have lots of solutions by now. So it won't be a problem when I say: DON'T DO THIS IN SAS. SAS is a great product. But it is not a systems administration tool. You should be doing this with a language that will let you do error-checking, and you should be checking your error retu...

Re: Copy from one directory in SAS to another, #3
On Mon, 22 Jan 2007 11:22:14 -0500, Jake Bee <johbee@GMAIL.COM> wrote: >Does anyone have any ideas on how to copy files from >one directory to another, using SAS, in DOS, but >with renaming the new file in the new directory. >(The new file name has the first 6 bytes removed.) > >Thanks for any ideas! > >Jake Here is another approach. I like Mike's solution too. I was thinking that Mike's solution will be much faster since mine will have to execute a separate data step for each file. However, I noticed that while mine was slower it wasn't that much sl...

Re: Copy from one directory in SAS to another, #4
Venky, That's one of the great things about SAS -- so many ways to do basically the same thing! ;-) I do try to avoid approaches that run one DATA step per whatever, since it seems inefficient and also can generate a large volume of messages to the log. However, I think that Ya Huang's solution would have us both beat. By first generating and then executing a .bat file, he avoids even the overhead of a separate system call for each file to be copied. Another approach worth considering that I also suspect would beat mine in terms of performance would be to access the underlying W...

Re: Copy from one directory in SAS to another, #7
I don't know if it'd be suitable for the OP's task, but for straight-ahead synching of drives on windows, consider the Robocopy utility--it's easily run as a scheduled task... -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Johnson, David Sent: Tuesday, January 23, 2007 11:43 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Copy from one directory in SAS to another, but renaming the output file The "other Dave" and I always have spirited discussions about this. I didn't see the original posting, I presume it was earlier...

Re: Copy from one directory in SAS to another, #6
The "other Dave" and I always have spirited discussions about this. I didn't see the original posting, I presume it was earlier in the month. I have just over 1Tb of data, logs, programs and documents sitting on an external laCie drive that I need replicated daily to a server. Issues of performance, network load and so on are involved and beyond the scope of the list. I also had problems with Xcopy and various other utilities, so I wrote the synchronisation process in SAS. It uses the Windows CreateDirectory and CopyFile APIs (in SAS macros) to replicate folder structure, ma...

Re: Copy from one directory in SAS to another, #2
Jake, I would try CALL SYSTEM -- something like the following: %LET OLDDIR = c:\junk\OldDir\; %LET NEWDIR = c:\junk\NewDir\; OPTIONS NOXWAIT XSYNC XMIN; DATA _NULL_; LENGTH OldName NewName $ 200 Command $ 1024; INFILE CARDS TRUNCOVER; INPUT OldName $CHAR200.; NewName = SUBSTR(OldName,7); Command = 'COPY "' || "&OldDir" || TRIM(OldName) || '" "' || "&NewDir" || TRIM(NewName) || '"'; CALL SYSTEM (Command); * PUT _ALL_; CARDS; 123456OneFile.txt 123456AnotherFile.txt RUN; Mike Rhoads Westat RhoadsM1@Westat.com -----Origin...

Re: can we copy files from one folder to another inside the sas
SAS-Learner , Yes you can look up the X command or Call System and that allows you to issue a operating system command. One of mine for a current project look like: Call System( 'cp ' || Compress( BaseStub || '/Base/' || I || '.sas' ) || ' ' || Compress( NewFolder || '/' || I || '.sas' ) ) ; Toby Dunn To sensible men, every day is a day of reckoning. ~John W. Gardner The important thing is this: To be able at any moment to sacrifice that which we are for what we could become. ~Charles DuBois Don't get your knickers in a knot. Not...

Re: can we copy files from one folder to another inside the sas #2
Hi, If you already have a common area, would not the %INCLUDE be handy? or are you grabbing the common template and then modifying it? in that case you can use the SAS x command to make system calls externally to SAS, or you can copy the file internally in SAS with code such as: * copy text file ; data _null_; infile 'c:\temp\abc.sas'; file 'c:\temp\xyz.sas'; input; put _infile_; run; Hope this is helpful. Mark Terjeson Senior Programmer Analyst, IM&R Russell Investment Group Russell Global Leaders in Multi-Manager Investing -----O...

File permissions; copying file from one directory to another
Hey guys... I'm a bit inexperienced with Linux, so I've been struggling with this scenario; I have a web app that creates a temporary data file (under the web daemons user info - apache) in the temp directory, called - for example - bla Its just a file with some text in it. The web app creates the data file, and then I want to move it to another directory, /var/spool/processor/outgoing I'm getting permission denied trying to copy "bla" from the temp directory (/var/tmp) to the above directory. I've set the "outgoing" directory prermissions world writea...

Re: PC SAS 9.1
> From: Jon Hayward > Is there a setting in PC SAS so that whichever directory I > save my .sas file to, SAS will automatically go there when I > want to save my .log and .lst files? > > Currently I must specify each location. While I am sure that > there is a reason for this, I am hoping that there might be a > setting to allow me to specify that I want SAS to remember my > current active location for the duration of that session... > So the next time I open SAS, I will perhaps save a different > .sas file to a different location and then SAS will know to >...

Re: PC SAS 9.1
Hi Jon, If you run SAS in batch mode the dir the .sas file is in will by default be the dir where the .log and .lst files will be left. Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld My computer remains home while I will attend PhUSE 2006 in Dublin. On Tue, 12 Sep 2006 09:23:15 -0400, Jon Hayward <jhayward1@BABSON.EDU> wrote: >Hi - > >Is there a setting in PC SAS so that whichever directory I save my .sas >file to, SAS will automatically go there when I want to save my .log >and .lst files? > >Currently...

Copy from one directory in SAS to another,
Does anyone have any ideas on how to copy files from one directory to another, using SAS, in DOS, but with renaming the new file in the new directory. (The new file name has the first 6 bytes removed.) Thanks for any ideas! Jake Jake, I would try CALL SYSTEM -- something like the following: %LET OLDDIR = c:\junk\OldDir\; %LET NEWDIR = c:\junk\NewDir\; OPTIONS NOXWAIT XSYNC XMIN; DATA _NULL_; LENGTH OldName NewName $ 200 Command $ 1024; INFILE CARDS TRUNCOVER; INPUT OldName $CHAR200.; NewName = SUBSTR(OldName,7); Command = 'COPY "' || "&OldDir" || TRIM(OldName) ...

copying programs/files from one partition to another
What is the easiest way to copy programs or files from one partition to another on an i5. Both are at V5R4, however, they each have a different tape drive model. Thanks, ga ga nospam@nospam.fmctc.com il 02/04/2009 17.35, Scrive ga 43502696: > What is the easiest way to copy programs or files from one partition > to another on an i5. Both are at V5R4, however, they each have a > different tape drive model. > > Thanks, > ga > > ga > nospam@nospam.fmctc.com Assuming you have a virtual lan betwenn partition, if you have Object Connect (that's an OS400 free opto...

Copy files and folders from one directory into another
I have files in myurl.com/myfolder and I would like to copy all of them into myurl.com/newfolder I'd like to copy all of the subdirectories and files that are in /myfolder and I would like to be able to use a form of some sort to name the file I want to copy, and create the folder I'd like to copy it to, such as newfolder. How can I use a form to create a new folder on the server? How can I use a form to name the old folder I want to copy everything from, then create the name of the new folder I want to copy everything into, and then copy? If anyone can help, I'd be VERY app...