On Fri, 10 Sep 2010 08:56:33 -0400, Marcos Sanches <firstname.lastname@example.org> wrote:
>I am using the code below to read a pipe delimited file. and here you have
>an example of a data line that is not being read correctly.
>"XXX"|"MARTIN DARVIN "DAN" DXXXX-2248"|"0"|"1"|"Client 2"|"GG"...
>SPSS wont read the whole piece "MARLY DARVIN "DAN" DXXXX-9778" in a single
>variable, as it should. I will instead consider the double quota in the
>middle of the string as a delimiter and split the string there and mess up
>everything further in the line.
>My questions -
>Is there a way to fix this so that SPSS will only cut the string at the
>Is this a problem with SPSS or is it a problem with the data file that
>should not have double quotas other then the qualifiers?
>Note - I considered replacing double quotes by a blank and the file would no
>longer have qualifiers, which I think would solve the problem, but the file
>is huge and this would be a time consuming task.
>Follow the reading syntax:
>GET DATA /TYPE = TXT
> /FILE = 'P:\MRCE\01
> /DELCASE = LINE
> /DELIMITERS = "|"
> /QUALIFIER = '"'
> /ARRANGEMENT = DELIMITED
> /FIRSTCASE = 2
> /IMPORTCASE = ALL
> /VARIABLES =
> X1 A37
>Thanks a lot!
Here's one way to skin the cat.
You'll want to nuke the BEGIN DATA... END DATA and read external file.
You'll have to modify the string variable lengths later.
You will also want to alter the vector length from 6 to your variable count
and the A40 to your longest embedded string.
SUBSTR may need to be changed to CHAR.SUBSTR -or maybe not-???
* Another General Parser *.
* NON PiThong version ;-)
DATA LIST / X 1-255 (A).
"XXX"|"MARTIN DARVIN "DAN" DXXXX-2248"|"0"|"1"|"Client 2"|"GG"
VECTOR PARSED(6, A40).
IF #1>0 PARSED(#0)=SUBSTR(X,1,#1-1).
END LOOP IF #1=0.
MATCH FILES / FILE * / DROP X.
PARSED2: "MARTIN DARVIN "DAN" DXXXX-2248"
PARSED5: "Client 2"
Number of cases read: 1 Number of cases listed: 1
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
For a list of commands to manage subscriptions, send the command