Question Regarding Importing Comma Delimited and Fixed Width Text Files

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Question Regarding Importing Comma Delimited and Fixed Width Text Files

Justin Meyer-3
I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.

 

Thank you for any help you can provide.

 

____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________

 

====================To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

Marks, Jim
Justin:

You can specify the blank ' ' as a delimiter.

I created a sample csv file with one row of data:
tct,12,12 24 36.

This syntax generate the correct data file:

GET DATA  /TYPE = TXT
 /FILE = 'C:\Book8.csv'
 /DELCASE = LINE
 /DELIMITERS = ",  "  /* note the space */
 /ARRANGEMENT = DELIMITED
 /FIRSTCASE = 1
 /IMPORTCASE = ALL
 /VARIABLES =
 V1 A3
 V2 f2.0
 V3 F2.0
 V4 F2.0
 V5 F2.0
.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.

Note that this still requires you to name and format all the variables
  V3 F2.0
  V4 F2.0
  V5 F2.0
in the example above.

Note also this treat all spaces as separate variables-- if you have
other text variables for example they could get split.

I suggest using the text import wizard-- enter a space as the "other"
choice for delimiters. The wizard also has steps to identify variable
names, formats and widths. (That is what I used to generate the syntax.)

good luck
--jim


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Monday, November 19, 2007 5:29 PM
To: [hidden email]
Subject: Question Regarding Importing Comma Delimited and Fixed Width
Text Files

I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.



Thank you for any help you can provide.



____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________



=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command SIGNOFF SPSSX-L For a list
of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

ViAnn Beadle
In reply to this post by Justin Meyer-3
Do the subtest scores always start in the same column? What do they look
like--are they numbers or something else?

It's fairly easy to split the 30 character string into separate variables
via syntax--that should not be prone to errors. The solution depends upon
more information from you.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Monday, November 19, 2007 4:29 PM
To: [hidden email]
Subject: Question Regarding Importing Comma Delimited and Fixed Width Text
Files

I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.



Thank you for any help you can provide.



____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________



=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

Maguin, Eugene
In reply to this post by Justin Meyer-3
Justin,

Perhaps you've considered this already but an alternative is to import the
data using a fixed format. If your data were

12,234,4566,18234567

The format would be f2.0,1x,f3.0,1x,f4.0,1x,4f2.0

Of course, a fixed format won't work if the comma separated fields vary in
width.

Taking apart a string field is easy if the component elements all have the
same width as in 15f2.0. One way is a loop structure

*  chunk is the a30 variable holding the 15f2.0 component variables.
Vector score(15,f2,0).
Loop #i=1 to 15.
+  compute #j=2*(#i-1)+1.
+  compute score(#i)=number(substring(chunk,#j,2),f2.0).
End loop.

Delete variables chunk.


Having the data resent may be easier and would allow you the opportunity to
tell the sender that they should have consulted with you beforehand about
file format. At the same time it punishes you.


Gene Maguin

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

Justin Meyer-3
In reply to this post by ViAnn Beadle
ViAnn:

The characters always start in the same column within the string. They
are always numbers. Example: JohnDoe,123701110517,ImaginarySchool. In
this example, The student's name is John Doe, subtest score 1 is 12,
subtest score 2 is 37, subtest 3 score is 01, subtest 4 score is 11 and
subtest 5 score is 05, subtest 6 score is 17, and the student goes to
Imaginary School. The scores always take up the same number of
characters, i.e., score 1 is always the first and second characters
after the comma, score 2 is always the third and fourth characters after
the comma, but because the student name will be a different length each
time, the number of characters in from the very beginning will always be
different. Thanks for your help.

____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________

-----Original Message-----
From: ViAnn Beadle [mailto:[hidden email]]
Sent: Tuesday, November 20, 2007 7:57 AM
To: Justin Meyer; [hidden email]
Subject: RE: Question Regarding Importing Comma Delimited and Fixed
Width Text Files

Do the subtest scores always start in the same column? What do they look
like--are they numbers or something else?

It's fairly easy to split the 30 character string into separate
variables
via syntax--that should not be prone to errors. The solution depends
upon
more information from you.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Monday, November 19, 2007 4:29 PM
To: [hidden email]
Subject: Question Regarding Importing Comma Delimited and Fixed Width
Text
Files

I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.



Thank you for any help you can provide.



____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________



=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

Justin Meyer-3
In reply to this post by Marks, Jim
Jim:

I should have included an example in my initial post. I don't have any
spaces between the subtest scores. Example:
JohnDoe,123701110517,ImaginarySchool. In this example, the student's
name is John Doe, subtest score 1 is 12, subtest score 2 is 37, subtest
3 score is 01, subtest 4 score is 11 and subtest 5 score is 05, subtest
6 score is 17, and the student goes to Imaginary School. The scores
always take up the same number of characters, i.e., score 1 is always
the first and second characters after the comma, score 2 is always the
third and fourth characters after the comma, but because the student
name will be a different length each time, the number of characters in
from the very beginning will always be different. Thanks for your help.

____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Marks, Jim
Sent: Monday, November 19, 2007 6:02 PM
To: [hidden email]
Subject: Re: Question Regarding Importing Comma Delimited and Fixed
Width Text Files

Justin:

You can specify the blank ' ' as a delimiter.

I created a sample csv file with one row of data:
tct,12,12 24 36.

This syntax generate the correct data file:

GET DATA  /TYPE = TXT
 /FILE = 'C:\Book8.csv'
 /DELCASE = LINE
 /DELIMITERS = ",  "  /* note the space */
 /ARRANGEMENT = DELIMITED
 /FIRSTCASE = 1
 /IMPORTCASE = ALL
 /VARIABLES =
 V1 A3
 V2 f2.0
 V3 F2.0
 V4 F2.0
 V5 F2.0
.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.

Note that this still requires you to name and format all the variables
  V3 F2.0
  V4 F2.0
  V5 F2.0
in the example above.

Note also this treat all spaces as separate variables-- if you have
other text variables for example they could get split.

I suggest using the text import wizard-- enter a space as the "other"
choice for delimiters. The wizard also has steps to identify variable
names, formats and widths. (That is what I used to generate the syntax.)

good luck
--jim


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Monday, November 19, 2007 5:29 PM
To: [hidden email]
Subject: Question Regarding Importing Comma Delimited and Fixed Width
Text Files

I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.



Thank you for any help you can provide.



____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________



=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command SIGNOFF SPSSX-L For a list
of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

ViAnn Beadle
In reply to this post by Justin Meyer-3
Read the text data as comma delimited (as you have already tried) but make
sure that the scorestring is read as alphanumeric. Then you can trundle
through the string, two characters at a time to pluck out your score
variables:

VECTOR score(15).
LOOP #i=1 to 30 by 2.
COMPUTE score(#i)=NUMBER(SUBSTRING(scorestring,#i,2),f2.0).
END LOOP.

Here's what's happening:

The VECTOR command creates 15 variables.
The LOOP sets an index value which is 1, 3, 5, ...
The COMPUTE command use the SUBSTRING function to pick up 2 characters from
the scorestring variable starting at the index value. It then applies the
NUMBER function to convert the string to a number.


-----Original Message-----
From: Justin Meyer [mailto:[hidden email]]
Sent: Tuesday, November 20, 2007 7:29 AM
To: ViAnn Beadle; [hidden email]
Subject: RE: Question Regarding Importing Comma Delimited and Fixed Width
Text Files

ViAnn:

The characters always start in the same column within the string. They
are always numbers. Example: JohnDoe,123701110517,ImaginarySchool. In
this example, The student's name is John Doe, subtest score 1 is 12,
subtest score 2 is 37, subtest 3 score is 01, subtest 4 score is 11 and
subtest 5 score is 05, subtest 6 score is 17, and the student goes to
Imaginary School. The scores always take up the same number of
characters, i.e., score 1 is always the first and second characters
after the comma, score 2 is always the third and fourth characters after
the comma, but because the student name will be a different length each
time, the number of characters in from the very beginning will always be
different. Thanks for your help.

____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________

-----Original Message-----
From: ViAnn Beadle [mailto:[hidden email]]
Sent: Tuesday, November 20, 2007 7:57 AM
To: Justin Meyer; [hidden email]
Subject: RE: Question Regarding Importing Comma Delimited and Fixed
Width Text Files

Do the subtest scores always start in the same column? What do they look
like--are they numbers or something else?

It's fairly easy to split the 30 character string into separate
variables
via syntax--that should not be prone to errors. The solution depends
upon
more information from you.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Monday, November 19, 2007 4:29 PM
To: [hidden email]
Subject: Question Regarding Importing Comma Delimited and Fixed Width
Text
Files

I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.



Thank you for any help you can provide.



____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________



=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

Oliver, Richard
In reply to this post by Justin Meyer-3
Assuming that the absolute position of each variable is not fixed in each record (e.g., subset scores always start in column position 9), then you need to read the subsets scores as a single string variable, and then extract the various components with the substr function and convert the results back to numbers. Alternatively, you could read it as a number and use numeric functions to extract the components, but I think string functions might be simpler in this case. For example, assuming the string variable containing all the subset info is called stringvar:

compute subtest1=number(substr(stringvar,1,1),f1).
compute subtest1_score=number(substr(stringvar,2,2),f2).
compute subtest2=number(substr(stringvar,4,1),f1).
etc.

Code not tested, but I think it's basically correct.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Justin Meyer
Sent: Tuesday, November 20, 2007 8:34 AM
To: [hidden email]
Subject: Re: Question Regarding Importing Comma Delimited and Fixed Width Text Files

Jim:

I should have included an example in my initial post. I don't have any
spaces between the subtest scores. Example:
JohnDoe,123701110517,ImaginarySchool. In this example, the student's
name is John Doe, subtest score 1 is 12, subtest score 2 is 37, subtest
3 score is 01, subtest 4 score is 11 and subtest 5 score is 05, subtest
6 score is 17, and the student goes to Imaginary School. The scores
always take up the same number of characters, i.e., score 1 is always
the first and second characters after the comma, score 2 is always the
third and fourth characters after the comma, but because the student
name will be a different length each time, the number of characters in
from the very beginning will always be different. Thanks for your help.

____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Marks, Jim
Sent: Monday, November 19, 2007 6:02 PM
To: [hidden email]
Subject: Re: Question Regarding Importing Comma Delimited and Fixed
Width Text Files

Justin:

You can specify the blank ' ' as a delimiter.

I created a sample csv file with one row of data:
tct,12,12 24 36.

This syntax generate the correct data file:

GET DATA  /TYPE = TXT
 /FILE = 'C:\Book8.csv'
 /DELCASE = LINE
 /DELIMITERS = ",  "  /* note the space */
 /ARRANGEMENT = DELIMITED
 /FIRSTCASE = 1
 /IMPORTCASE = ALL
 /VARIABLES =
 V1 A3
 V2 f2.0
 V3 F2.0
 V4 F2.0
 V5 F2.0
.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.

Note that this still requires you to name and format all the variables
  V3 F2.0
  V4 F2.0
  V5 F2.0
in the example above.

Note also this treat all spaces as separate variables-- if you have
other text variables for example they could get split.

I suggest using the text import wizard-- enter a space as the "other"
choice for delimiters. The wizard also has steps to identify variable
names, formats and widths. (That is what I used to generate the syntax.)

good luck
--jim


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Monday, November 19, 2007 5:29 PM
To: [hidden email]
Subject: Question Regarding Importing Comma Delimited and Fixed Width
Text Files

I am a beginning SPSS user. I am trying to import a text file (.txt)
into SPSS 15.0. The text file is comma delimited except for the subtest
scores. There are 15 subtests in the data, each of which is represented
by a two character score. These two character scores are in a 30
character string, with no commas or anything else separating the scores.
When I attempt to import this data into SPSS as a comma delimited file,
I get one 30 character variable that includes the data from all 15
subtests rather than 15 two character variables. Can I fix this problem
when I import the data? I would prefer to avoid breaking the one
variable into other variables after it is imported as there are a large
number of these (not just one set of 15 subtests) and it would be prone
to error. It is likely that I can have the test data resent as
completely comma delimited or fixed width but there must be a way to
work with what I have. Why would this format be the default way to
receive the data? Wouldn't a file that was completely comma delimited or
fixed width make more sense? FYI- I have very little experience with
syntax but I am willing to work with it if that is the only way.



Thank you for any help you can provide.



____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________



=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command SIGNOFF SPSSX-L For a list
of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Importing Comma Delimited and Fixed Width Text

Richard Ristow
In reply to this post by Justin Meyer-3
At 06:28 PM 11/19/2007, Justin Meyer wrote:

>I am trying to import a text file (.txt) into SPSS 15.0. The text
>file is comma delimited except for the subtest scores. There are 15
>subtests in the data, each of which is represented by a two
>character score. These two character scores are in a 30 character
>string, with no commas or anything else separating the scores. When
>I attempt to import this data into SPSS as a comma delimited file, I
>get one 30 character variable that includes the data from all 15
>subtests rather than 15 two character variables.

Right; and, you'll understand, this is inevitable. SPSS's reasoning
is that 'comma-delimited' means comma-delimited, period; no comma, no
new variable.

>Can I fix this problem when I import the data?

Can you give us a few data lines? Sometimes comma-delimited files
actually have fixed widths of each variable, and can be read as
fixed-width files. First, see whether you can do it that way.

>I would prefer to avoid breaking the one variable into other
>variables after it is imported as there are a large number of these
>(not just one set of 15 subtests) and it would be prone to error.

That could at least be alleviated by making the logic a macro.
Unfortunately, that means getting into syntax and macros at once, and
that's a couple of big jumps. OR, write and test the syntax once;
they copy it as many times as you like in a text editor, and change
the variable names.

The syntax, by the way, needn't be very complicated. Something like
this, not tested. (It produces the subtest scores as two-character
strings; if you want them as numbers, the logic must be extended a little.

If the variable is TstScore, then

VECTOR TstSub(15,A2) /* The 15 subscore variables */.
LOOP #SubsIdx = 1 TO 15.
.  COMPUTE TestSub(#SubsIdx)
           = SUBSTR(TstScore,2*#SubsIdx-1,2).
END LOOP.

>It is likely that I can have the test data resent as completely
>comma delimited or fixed width but there must be a way to work with
>what I have.

There are ways, as I've said; but having the data resent would
probably be the second thing I'd try, if you can't read the
comma-delimited file as fixed-form.

>Why would this format be the default way to receive the data?
>Wouldn't a file that was completely comma delimited or fixed width
>make more sense?

It would make sense, but a lot of things that would make sense, don't happen.

To make a wild guess: Whoever is preparing the data has some means of
scoring the tests that produces the set of subtest scores as the
30-character strings. THEN, instead of writing code to break them up
into separate fields, whoever it is simply writes the data as
comma-delimited in the simplest way, letting those 30-character
strings stay as single values.

Good luck!
Richard

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD