Login  Register

Re: read file names into spss

Posted by David Marso on Jan 11, 2012; 6:21pm
URL: http://spssx-discussion.165.s1.nabble.com/read-file-names-into-spss-tp5137141p5137617.html

**ALWAYS** post your error messages!!!!!
When I run your MACRO I get:
>Error.  Command name: GET DATA
>(2269) Failure opening file: d:\test\AJC\AJC-2000-1-1-a.txt
>This command not executed.
Confirm these files exist under the subdirectory d:\test\AJC

Zhenzhen Wang wrote
Hi,

My problem is a little bit complicated. I'll try to express it clearly.

1, I have a lot of text files. Actually each file represents a paper.

2, The rule of naming is "journal-year-issue-startpage-type". For example,
a paper published in Journal of Communication might be named as
"JOC-2000-1-20-a.txt".

3, I want to read these file names into spss, so that I can match or
compare them with references exported from database.

4, I think the first step is to read each file name into a spss file, then
add the files up. I wrote a syntax to do the first step. But I keep getting
error messages.
   The red part is where I got error messages. I want to attach my syntax
and test data but the mail system does not allow it, so I attach it as part
of this letter.

Can you help me? Thank you very much!

Wang Zhenzhen


*Each test file contains some words, but I don't really care what are the
words. The names of the test files is:*
AJC-2000-1-1-a
AJC-2000-1-7-b
AJC-2000-1-2-a
AJC-2000-1-2-b
(they are in a folder named AJC)
EJOC-2000-1-5-a
EJOC-2000-2-3-a
EJOC-2000-2-10-b
(they are in a folder named EJOC)

*The syntax is as below.*


define !path()'d:\test\'
!enddefine.

set mprint=off.
define !readname (journal=!charend('/')/type=!cmdend)
   !do !var1=1 !to 2.
       !do !var2=1 !to 10.
               get data
                   /TYPE=TXT

 /FILE=!path+!QUOTE(!concat(!journal,'\',!journal,'-2000-',!var1,'-',!var2,'-',
!type,'.txt'))
                   /DELCASE=VARIABLES 1
                   /DELIMITERS=' '
                   /ARRANGEMENT=DELIMITED
                   /FIRSTCASE=1
                   /IMPORTCASE=first 1
                   /VARIABLES=word A100.
        string filename (a50).
        compute filename=!concat(!journal, '-2000-', !var1,'-',!var2,'-',
!type).
               save
outfile=!path+!QUOTE(!concat(!journal,'\',!journal,'-2000-',
!var1,'-',!var2,'-', !type,'.sav'))
           !doend.
       !doend.
!enddefine.

set mprint=on.
!readname journal=AJC/type=a.
!readname journal=AJC/type=b.
!readname journal=EJOC/type=a.
!readname journal=EJOC/type=b.

--
Department of Media and Communication
City University of Hong Kong


--
Department of Media and Communication
City University of Hong Kong
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"