Date: Wed, 19 May 2004 09:10:56 -0400
Reply-To: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Subject: Re: How to set up libnames and filenames with a twist
Content-Type: text/plain; charset=ISO-8859-1
Hi, Lou,
You are absolutely right. x ‘cd (some directory)’; works! It works even
when the (some directory) is on another machine in the network or another
drive.
Also works are:
x cd c:\temp; /* no quotation marks */
x cd \\node\c$\temp; /* c:\temp directory on a machine called node */
x cd d:\d1\d2\..\..\d3; /* up-and-down */
x cd \\node\c$\documents and settings\chang;
/* embedded blanks with no quotes */
x cd //node/c$\documents and settings\chang\My document;
/* both / and \ works or you can even mix them.
Capitalization does not matter either */
When you x cd to a non-existing directory, it fails silently. You can
check if x cd was successful by checking the automatic macro variable
&sysrc. (zero means success), immediately after the x statement.
I am so embarrassed that I was totally wrong and apologize to you all
since I wasted band widths and lowered the signal to noise ratio.
Personally I am glad that I now know something I did not know before.
Thanks Lou! I will call this “Lou’s cool x cd” technique!
Cheers,
Chang
>I've commented below.
>
>----- Original Message -----
>From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
>To: <SAS-L@LISTSERV.UGA.EDU>; <lpogodajr292185@COMCAST.NET>
>Sent: Tuesday, May 18, 2004 2:47 AM
>Subject: Re: How to set up libnames and filenames with a twist
>
>
>> On Mon, 17 May 2004 21:07:22 -0400, Lou <lpogodajr292185@COMCAST.NET>
>> wrote:
>>
>> >First suggestion - Using mapped drive letters for network addresses
means
>> >the program will only perform as expected on machines with identical
>> >mapping. Unless your place uses rigidly enforced mappings across all
>> >machines, this can lead to unexpected results
>> >
>> >Second suggestion - For many (most?) file applications, there's no need
>to
>> >separately issue filename statements for each file. Directories (or
>> >folders, if you prefer) are "aggregate storage locations" and
individual
>> >files can be accessed along the lines of the following:
>> >
>> >filename in '\\servername\level1a\level1b\level1c';
>> >filename out '\\servername\level2a\level2b\level2c';
>> >data fee;
>> > infile in(your input file name here);
>> > file out(your output file name here);
>> >
>> >Third suggestion - though libnames and filenames are usually given as
>> >absolute addresses, you can use relative addresses for both. If a
>project
>> >is located in a folder on a network drive with different components
>> >distributed in various subfolders, you can change the current folder to
>> that
>> >project folder and then use relative addresses to each component. For
>> >instance, this example switches the current folder to the root on the C
>> >drive, but it could just as easily switch to a network folder.
>> >
>> >x 'cd c:\';
>> >filename in 'all data\test.txt';
>> >libname out 'all data';
>> >data out.test;
>> > infile in pad;
>> > input @1 string $50.;
>> >
>> >run;
>> >
>> >The above example reads a text file with the full address of "C:\all
>> >data\test.txt" and writes an output data set with the name "test" to
>> folder
>> >"C:\all data". If you use dot (.) for the current directory and
double-
>> dot
>> >(..) for the directory one level up from the current directory in the
>> >filename or libname statements, you can step up and down the folder
>> >hierarchy.
>> >
>> >Much neater, in my opinion, than macro variables.
>>
>> Hi, Lou,
>>
>> Thank you for the wonderful suggestions. I learn a lot from your posts.
>>
>> I do agree with you in that this is much neater.Well, I know I am
arguing
>> over tiny points -- but for argument's sake, here are my reasons for
>> preferring the macro approach.
>>
>> I guess, in sum, Windows is not very nice -- it does not seem to allow
us
>> to apply all three of otherwise valid suggestions together. For
instance:
>>
>> On my machine, I don't think I can do
>>
>> x 'cd \\node\directory';
>>
>> unless I map the directory to a drive letter.
>
>On my machine, I can. I'm using SAS 8.2 and Windows 2000 Pro. I have in
>the past (years past) been on some machine or other that required the
>command to be in double quotes, instead of single. In any case, it's not
a
>matter of belief - it takes but a few seconds to try.
>
>> If my current working directory is, say, under d:, I cannot even cd
across
>> anorhter drive, say c:, either.
>
>Again, on my machine, and for that matter on any machine in my office,
this
>presents no problem. I write programs that are run by numerous people,
and
>no one has had any difficulty running them in this respect.
>
>As to whether or not your machine is capable of this operation, you might
>try something along the lines of the following, just to illustrate the
>point. Open Word. Start to record a macro. Open a document at some
>network address by going through the file/open dialog from the menu bar.
>Save the document to some other network location by going through the
>file/save as dialog from the menu bar. Halt the macro recording. Edit
the
>macro you just recorded. You'll see the machine changing directories in
the
>recorded macro. All you're trying to do is replicate this behavior in the
>SAS program.
>
>> x 'cd c:\my';
>>
>> In this case, however, there is an ugly shortcuts, i.e.,
>>
>> x 'c:';
>> x 'cd my';
>>
>> or
>>
>> x 'c:&cd my';
>>
>> So, it seems that we are stuck with the following in practice,
>>
>> >filename in '\\servername\level1a\level1b\level1c';
>> >filename out '\\servername\level2a\level2b\level2c';
>>
>> And I think in this case, it is most common to have both the filenames
>> share the parent directory the same upto the last one -- if so, then why
>> not write the possibly long and complicated part only once in %let and
use
>> the macro var? :-)
>
>I NEVER actually write network addresses - well, almost never. I have
>shortcuts that open a windows explorer window on various network
>destinations (ones that are the "root" of my current projects) and I've
>confured explorer to show the address bar. If I need a network address, I
>click on the shortcut, highlight the address in the address bar of the
>explorer window, and paste it into the program. It might sound slightly
>complex, but the net result is faster than typing in one or several macro
>variable values, and less error prone by far.
>
>> Cheers,
>> Chang
>
>Glad you found my reply interesting.
|