Discussion:
File Handle yielding error in INCLUDE command
(too old to reply)
Hari
2005-05-10 12:31:11 UTC
Permalink
Hi,

I downloaded Raynald's book from SPSS site and came across the Include
command and wanted to try it out.

I created a folder named examples with a sub- folder Commands in it and
then renamed one of my huge Syntax file as "report groups.sps" and
pasted in --c:\examples\commands-- folder.

Then I ran the below syntax.

FILE HANDLE commands /NAME='c:\examples\commands'.

INCLUDE FILE = "commands\report groups.sps".

The error I get is
Error # 3038 in column 28. Text: c:\examples\commands
The file specification given for the NAME subcommand is not valid.
This command not executed.
INCLUDE FILE = "commands\report groups.sps".
Error # 34 in column 16. Text: commands\report groups.sps
SPSS cannot access a file with the given file specification. The file
specification is either syntactically invalid, specifies an invalid
drive,
specifies a protected directory, specifies a protected file, or
specifies a
non-sharable file.
This command not executed.
On the other hand If I comment out, the --File Handle-- line above and
run the bwlow syntax

*FILE HANDLE commands /NAME='c:\examples\commands'.

INCLUDE FILE = "c:\examples\commands\report groups.sps".

then everything works fine.

Please tell why the File Handle doesnt work.

Regards,
Hari
India
Richard Ulrich
2005-05-10 16:59:17 UTC
Permalink
On 10 May 2005 05:31:11 -0700, "Hari" <***@yahoo.com> wrote:

[snip, detail]
Post by Hari
On the other hand If I comment out, the --File Handle-- line above and
run the bwlow syntax
*FILE HANDLE commands /NAME='c:\examples\commands'.
INCLUDE FILE = "c:\examples\commands\report groups.sps".
then everything works fine.
Please tell why the File Handle doesnt work.
Your "File Handle" just shows a directory, and that is not
how it works.

"File Handle" wants to see a full file specification,
and then the "Include File" (I think) could use simply
the assigned name -- in your example, < commands >.

I think Raynald includes descriptions of how to build
a long file name so that early (root) directories don't have to
be spelled out in every reference. That might be useful to you.

Also, the whole name is not needed if the Included file
is in the "current" directory, if you have been running
a task that establishes a current directory. That is how
I've usually used "Include Files" in Windows. (On the
Digital VAX systems, it was convenient to use "logical
names" that defined directory structures.)
--
Rich Ulrich, ***@pitt.edu
http://www.pitt.edu/~wpilib/index.html
Moshe Braner
2005-05-11 16:22:42 UTC
Permalink
On Tue, 10 May 2005 12:59:17 -0400, Richard Ulrich
Post by Richard Ulrich
Also, the whole name is not needed if the Included file
is in the "current" directory, if you have been running
a task that establishes a current directory. That is how
I've usually used "Include Files" in Windows.
Windows in general (and MS applications) has destroyed the concept of
"current working directory (folder)", which I think is a big loss. As far
as SPSS goes, I have found that using relative pathnames (assuming a
current working folder) is unreliable. The method that works best for me
is to use the MS-DOS "SUBST" command to define a "drive letter" that
actually points to a folder. This MS-DOS command is still available
within a "command prompt" window in Windows XP. You can also put the
SUBST command in a "batch" file and make a Windows shortcut to it. Once
you define the drive letter like this, it is available in all windows,
e.g. within SPSS. Example syntax:

In the batch file:

subst x: c:\my\folder\subfolder

Then in SPSS:

get file='x:\filename.sav'.

include file='x:\somefile.sps'.
Hari
2005-05-13 15:08:18 UTC
Permalink
Hi Richard,

Thnx for the mail. Im sorry but not able to get your thoughts.

Im quoting you below.
Post by Richard Ulrich
I think Raynald includes descriptions of how to build
a long file name so that early (root) directories don't have to
be spelled out in every reference. That might be useful to you.
Actually this is what I wanted to do. I wanted to to use file handle so
that I need not mention the intial directory again and again.

My data files are in a different location as compared to my Syntax
files.

So I tried the below syntax.

FILE HANDLE masterdir1 /NAME='D:\Hari\DT\DT Wave 23\WORKING
FILES\DATA\SYNTAX\SYNTAX TO BE RUN IN ORDER'.
FILE HANDLE masterdir2 /NAME='D:\Hari\DT\DT Wave 23\WORKING
FILES\DATA\SYNTAX\SYNTAX TO BE RUN JUST BEFORE RUNNING FOR TABLES'.

INCLUDE FILE = "masterdir1\02.format syntax - wave 23.SPS".
INCLUDE FILE = "masterdir1\03.reclassification.SPS".
INCLUDE FILE = "masterdir1\04. Wave 23 - RECODE SYNTAX .sps".
INCLUDE FILE = "masterdir1\07.Q1a Q10 autocoding macro Mar 14.SPS".
INCLUDE FILE = "masterdir1\07A. Wave 22 - Q1-Q4-Q7 Macro - RUN AFTER
UPCODING ONLY.sps".
INCLUDE FILE = "masterdir1\09. Wave 21 - REMOVING NONE FROM Q21 - Jan
7.SPS".
INCLUDE FILE = "masterdir1\10. Wave 21 - Q21 Q22 Q23 Macro - RUN AFTER
UPCODING ONLY.SPS".
INCLUDE FILE = "masterdir1\07A. Wave 22 - Q1-Q4-Q7 Macro - RUN AFTER
UPCODING ONLY.sps".
INCLUDE FILE = "masterdir1\"11. Wave 21 - Q31a - Q32a cleaning
macro.SPS.
INCLUDE FILE = "masterdir1\12.Wave 23 - Syntax for cleaning within and
outside the base - 2005 04 15.sps".
INCLUDE FILE = "masterdir1\13.Inside and outside cleaning Syntax (More)
- Wave 23.sps".
INCLUDE FILE = "masterdir1\14. Correct Quota Version 2 Syntax -
Jan7'05.SPS".
INCLUDE FILE = "masterdir1\15.P35com and P36com syntax - jan 12.SPS".
INCLUDE FILE = "masterdir2\keep syntax.SPS".
INCLUDE FILE = "masterdir2\12 - MULTICODES REMOVING SYNTAX - Jan
7.SPS".
INCLUDE FILE = "masterdir2\13 - Wave 21 - COMBO SYNTAX - Jan10.sps".
INCLUDE FILE = "masterdir2\13 - Wave 22 - num SYNTAX - Mar 16.sps".
INCLUDE FILE = "masterdir2\Combo Variable for Q308A - Q308A2 and Q319 -
Q319A and Q320 - Q320A.SPS".
INCLUDE FILE = "masterdir2\Q1-Q7 Combo (With VSI).SPS".
INCLUDE FILE = "masterdir2\Q1-Q7 Combo (Without VSI).SPS".


But as said in my original post it generated errors.

How do I avoid mentioning/specifying initial directories again and
again and still be able to run the files. (I wanted to use the file
handle method because if I have to run these syntaxes from let's say my
home computer then the path of masterdir1 and masterdir2 would change
and in this case I would have to change only the file handle commands
in order to make it work).

Please guide me.

Regards,
hari
India
Richard Ulrich
2005-05-13 15:46:22 UTC
Permalink
Post by Hari
Hi Richard,
Thnx for the mail. Im sorry but not able to get your thoughts.
Im quoting you below.
Post by Richard Ulrich
I think Raynald includes descriptions of how to build
a long file name so that early (root) directories don't have to
be spelled out in every reference. That might be useful to you.
Actually this is what I wanted to do. I wanted to to use file handle so
that I need not mention the intial directory again and again.
Well, I tried to say, "YOU CAN'T USE FILE HANDLE THAT WAY."
You use file handle to give the whole thing, then use that name -

FILE HANDLE master1 /Name= 'D:\hari\dt\dt\working\something.sps'.
...
INCLUDE FILE= master1. /* no quotes around master1.

You can see look for Raynald's help on how to build names.
Or, you can use the other reply to your note,
which gives something better.

=== from Moshe Braner's Reply
In the batch file:

subst x: c:\my\folder\subfolder

Then in SPSS:

get file='x:\filename.sav'.
include file='x:\somefile.sps'.
===

[snip]
Post by Hari
How do I avoid mentioning/specifying initial directories again and
again and still be able to run the files. (I wanted to use the file
handle method because if I have to run these syntaxes from let's say my
home computer then the path of masterdir1 and masterdir2 would change
and in this case I would have to change only the file handle commands
in order to make it work).
...

Moshe's answer meets that need. See his whole reply
for a broader context.
--
Rich Ulrich, ***@pitt.edu
http://www.pitt.edu/~wpilib/index.html
Bruce Weaver
2005-05-13 20:07:45 UTC
Permalink
Post by Richard Ulrich
Well, I tried to say, "YOU CAN'T USE FILE HANDLE THAT WAY."
You use file handle to give the whole thing, then use that name -
FILE HANDLE master1 /Name= 'D:\hari\dt\dt\working\something.sps'.
...
INCLUDE FILE= master1. /* no quotes around master1.
Here are some examples from the syntax reference manual:

FILE HANDLE thisMonthFile /NAME='c:\sales\data\july.sav'.
FILE HANDLE dataDirectory /NAME='c:\sales\data'.
GET FILE 'thisMonthFile'.
GET FILE 'dataDirectory\july.sav'.

I tried some similar examples, and found that if the file handle
includes the entire path AND file name, it works with or without the
quotes. That is, BOTH of the following work:

GET FILE 'thisMonthFile'.
GET FILE thisMonthFile.

But if the file handle gives only the path to the folder, the quotes
(AND the back-slash before the file name) are required.
--
Bruce Weaver
***@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
Richard Ulrich
2005-05-13 20:26:48 UTC
Permalink
Post by Bruce Weaver
Post by Richard Ulrich
Well, I tried to say, "YOU CAN'T USE FILE HANDLE THAT WAY."
You use file handle to give the whole thing, then use that name -
FILE HANDLE master1 /Name= 'D:\hari\dt\dt\working\something.sps'.
...
INCLUDE FILE= master1. /* no quotes around master1.
FILE HANDLE thisMonthFile /NAME='c:\sales\data\july.sav'.
FILE HANDLE dataDirectory /NAME='c:\sales\data'.
GET FILE 'thisMonthFile'.
GET FILE 'dataDirectory\july.sav'.
I tried some similar examples, and found that if the file handle
includes the entire path AND file name, it works with or without the
GET FILE 'thisMonthFile'.
GET FILE thisMonthFile.
But if the file handle gives only the path to the folder, the quotes
(AND the back-slash before the file name) are required.
Bless me! I never knew all that.

- My apologies -
The Original Poster was closer to a good solution than
I suspected. You can avoid that DOS involvement, and
get the same effect with File Handle.

This is going to be useful, especially without the
'default directory' available any more, as Moshe reports.

Googling groups doesn't find any post before now, where
Subst and File handle co-occur.
--
Rich Ulrich, ***@pitt.edu
http://www.pitt.edu/~wpilib/index.html
Bruce Weaver
2005-05-13 20:48:20 UTC
Permalink
Post by Richard Ulrich
Bless me! I never knew all that.
Me neither until just now.
Post by Richard Ulrich
- My apologies -
The Original Poster was closer to a good solution than
I suspected. You can avoid that DOS involvement, and
get the same effect with File Handle.
This is going to be useful, especially without the
'default directory' available any more, as Moshe reports.
Googling groups doesn't find any post before now, where
Subst and File handle co-occur.
Here's an example similar to the one in the original post (i.e., using
INCLUDE FILE). It depends on the existence of a syntax file "test
include file.SPS" in the C:\temp folder. (My include file just runs
frequencies on a few variables.)

* ------------------------------------------------ .
FILE HANDLE datapath /Name= 'C:\Program Files\SPSS'.
FILE HANDLE syntaxpath /Name= 'C:\temp'.

get file = 'datapath\1991 U.S. General Social Survey.sav'.
include file = "syntaxpath\test include file.SPS".
* ------------------------------------------------ .

I've been using macros to define paths to various folders (there's an
example of this on Ray's SPSS website); but this method looks just as
easy. And one advantage is that the file handle can be longer than 8
characters (at least in version 13).
--
Bruce Weaver
***@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
Jonathan Fry
2005-05-16 22:36:25 UTC
Permalink
Post by Hari
Hi,
I downloaded Raynald's book from SPSS site and came across the Include
command and wanted to try it out.
I created a folder named examples with a sub- folder Commands in it and
then renamed one of my huge Syntax file as "report groups.sps" and
pasted in --c:\examples\commands-- folder.
Then I ran the below syntax.
FILE HANDLE commands /NAME='c:\examples\commands'.
INCLUDE FILE = "commands\report groups.sps".
The error I get is
Error # 3038 in column 28. Text: c:\examples\commands
The file specification given for the NAME subcommand is not valid.
This command not executed.
INCLUDE FILE = "commands\report groups.sps".
Error # 34 in column 16. Text: commands\report groups.sps
SPSS cannot access a file with the given file specification. The file
specification is either syntactically invalid, specifies an invalid
drive,
specifies a protected directory, specifies a protected file, or
specifies a
non-sharable file.
This command not executed.
On the other hand If I comment out, the --File Handle-- line above and
run the bwlow syntax
*FILE HANDLE commands /NAME='c:\examples\commands'.
INCLUDE FILE = "c:\examples\commands\report groups.sps".
then everything works fine.
Please tell why the File Handle doesnt work.
--------------------
Allowing FILE HANDLE to name a directory (along with the CD command) was
added to SPSS in release 13, and Raynald used it in recent editions of his
book. If you have an earlier version, the changes you have already found
will be necessary.

Jonathan Fry
SPSS Inc.
Hari
2005-05-19 15:20:21 UTC
Permalink
Hi Jonathan,

Thnx for that crucial info.

As I mentioned in my original mail i have version 11, so that explains
why I was getting the error.

I was wondering why I couldnt get my syntax to work considering that
Bruce could get it done in his system.

Regards,
Hari
India
Bruce Weaver
2005-05-19 16:57:04 UTC
Permalink
Post by Hari
Hi Jonathan,
Thnx for that crucial info.
As I mentioned in my original mail i have version 11, so that
explains
Post by Hari
why I was getting the error.
I was wondering why I couldnt get my syntax to work considering that
Bruce could get it done in his system.
I should have mentioned in my earlier post that I'm running version 13
(under Win-doze XP Professional, SP2).
--
Bruce Weaver
***@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
Mike
2005-05-21 15:15:00 UTC
Permalink
Can't we use INSERT instead of INCLUDE? any difference?
Post by Bruce Weaver
I should have mentioned in my earlier post that I'm running version 13
(under Win-doze XP Professional, SP2).
Loading...