sas >> Copy a file from one directory to another from a SAS program?

by mlhoward » Fri, 01 Aug 2008 03:04:30 GMT

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

sas >> Copy a file from one directory to another from a SAS program?

by matt.pettis » Fri, 01 Aug 2008 03:58:51 GMT


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: XXXX@XXXXX.COM ] On Behalf Of
Mary
Sent: Thursday, July 31, 2008 2:05 PM
To: XXXX@XXXXX.COM
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

sas >> Copy a file from one directory to another from a SAS program?

by mlhoward » Fri, 01 Aug 2008 04:12:12 GMT

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: XXXX@XXXXX.COM =20
To: XXXX@XXXXX.COM ; XXXX@XXXXX.COM =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 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: XXXX@XXXXX.COM ] On Behalf Of
Mary
Sent: Thursday, July 31, 2008 2:05 PM
To: XXXX@XXXXX.COM
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

sas >> Copy a file from one directory to another from a SAS program?

by tj_noreply » Fri, 01 Aug 2008 04:21:11 GMT

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




program?

sas >> Copy a file from one directory to another from a SAS program?

by msz03 » Fri, 01 Aug 2008 04:23:30 GMT

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)

sas >> Copy a file from one directory to another from a SAS program?

by matt.pettis » Fri, 01 Aug 2008 04:39:06 GMT

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: XXXX@XXXXX.COM ]=20
Sent: Thursday, July 31, 2008 3:12 PM
To: Pettis, Matthew (Prof II&RS); XXXX@XXXXX.COM
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 tried:
X "exit";
and that did not work to close it. Would anyone know how to close it?
=20
-Mary

----- Original Message -----=20
From: XXXX@XXXXX.COM =20
To: XXXX@XXXXX.COM ; XXXX@XXXXX.COM =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 move the file:
=09
X "move /path/to/original /path/to/dest";
=09
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.
=09
Matt
=09
-----Original Message-----
From: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] On
Behalf Of
Mary
Sent: Thursday, July 31, 2008 2:05 PM
To: XXXX@XXXXX.COM
Subject: Copy a file from one directory to another from a SAS
program?
=09
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.
=09
-Mary
=09

sas >> Copy a file from one directory to another from a SAS program?

by datanull » Fri, 01 Aug 2008 04:41:45 GMT

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?

sas >> Copy a file from one directory to another from a SAS program?

by art297 » Fri, 01 Aug 2008 05:43:19 GMT

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
---------


program?

sas >> Copy a file from one directory to another from a SAS program?

by mlhoward » Fri, 01 Aug 2008 05:44:15 GMT

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 related tables; a patient level table that is a one to =
many join with a visit level table, where the patient is a foreign key =
on the visit table. =20

It is working great! Yes,=20
options noxwait;=20
did the trick on closing the DOS window automatically.=20


Thanks all.

-Mary

----- Original Message -----=20
From: data _null_,=20
To: XXXX@XXXXX.COM =20
Sent: Thursday, July 31, 2008 3:41 PM
Subject: Re: Copy a file from one directory to another from a SAS =
program?


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?


> 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: XXXX@XXXXX.COM
> To: XXXX@XXXXX.COM ; XXXX@XXXXX.COM
> 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: XXXX@XXXXX.COM ] On Behalf =
Of
> Mary
> Sent: Thursday, July 31, 2008 2:05 PM
> To: XXXX@XXXXX.COM
> 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
>

sas >> Copy a file from one directory to another from a SAS program?

by EdHeaton » Fri, 01 Aug 2008 21:12:06 GMT

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: XXXX@XXXXX.COM http://www.Westat.com




-----Original Message-----
From: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] On Behalf Of
Mary
Sent: Thursday, July 31, 2008 4:12 PM
To: XXXX@XXXXX.COM
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: XXXX@XXXXX.COM
To: XXXX@XXXXX.COM ; XXXX@XXXXX.COM
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: XXXX@XXXXX.COM ] On Behalf Of
Mary
Sent: Thursday, July 31, 2008 2:05 PM
To: XXXX@XXXXX.COM
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

Similar Threads

1. Copy from one directory in SAS to another,

2. weird "work" directory under programs directory using SAS/LE 4.1

I am running some code in batch using the SAS/LE executable "sas.exe"
and when the job finishes there is an empty "work" directory under the
programs directory. Can somebody give me some pointers as to why that
might be and how to avoid it?

Thanks,
Roland

3. SCL commands to copy external file to new directory

4. can we copy files from one folder to another inside the sas

can we tell SAS to copy .sas file from one folder to another folder . I know
this is function of the Operating system but Just curious to find out

I am thinking of the lines of

we have a couple of files that are located in common area called project
template and there are certain project specific files we need to copy the
template file from one study to another physically , so I am thinking is
there a way to tell sas to pick those common files (*.sas*) in a
certain folder to another folder .

thanks

5. Copy file from one server to another through IOM

6. How to run several SAS programs in one sas Program

Hi,

Is it possible to run several SAS programs in one sas Program. I can
use the %INCLUDE, but is there another way?

Tx

7. copy files with x copy

8. How can I copy the whole directory (library XX) to another

I have 200 datasets that I am pulling from Oracle Using libname staement
by creating a library XX.
now I want to copy everything  from the library XX to my computer hardrive
(C:\). How can I do it without using the dataset and libnames individually?