1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
*(Q) In some fields, data contains embedded Carriage Return characters. 
 The length of the value is
 the total length of the two or three lines.  In the full screen view of the
 data editor, the variable shows only the characters up to the first carriage
 return but if I move to the cell with the multiple lines, all the lines show
 up in the 'current cell' box near the top of the screen.  So, all the
 information is still there and I would like to convert the carriage returns
 into @ signs (or some other character) such that I can parse this
 information into lines.

*HELP:  can SPSS do a lookup for this special character.  

*(A) An initial response was posted to SPSSX-L list by Bjarte Aagnes on 2002/02/08.
* The following (improved) syntax was subsequently emailed to me by Bjarte.


************************************************************
Comments to : Bjarte Aagnes, aagnes@statinet.no

************************************************************

*Preliminary step 1: 
*read some example data 
with <cr><nl> = HEX 0d0a  and HEX 41-6 = A-F.



DATA LIST LIST /origin (AHEX30).

BEGIN DATA

410d0a4243440d0a4546

46450d0a4443420d0a0d0a410d0a

END DATA.

EXE.



*Preliminary step 2.

FORMAT origin (A15).  /*string variable with embedded cr><nl>*/  

************************************************************
*Start program: change string to AHEX and print to file.


FORMAT origin (AHEX30).      

PRINT OUTFILE=tmp.txt /origin.  

EXE.



************************************************************
*Read variable and parse.



DATA LIST FILE = "tmp.txt" / origin (A15).

DO IF (RINDEX(origin,"0D0A") > 0). 

+    LOOP #j=1 TO 100.  

+       STRING #str res (A30).

+        IF #j=1 #str=LTRIM(RTRIM(origin)). 

+        COMP #p = INDEX(#str,"0D0A").  

+        COMP res = CON(RTRIM(res), SUB(#str,1,#p-1)).

+        COMP #str = SUB(#str,#p+4).

+        IF (RINDEX(#str,"0D0A")) = 0 res = CON(RTRIM(res),#str). 

+    END LOOP IF RINDEX(#str,"0D0A")  =  0.

END IF.


PRINT OUTFILE=tmp2.txt /origin res.

EXE.



***********************************************************
*read and convert back to prefered format (A15). 



DATA LIST LIST FILE = "tmp2.txt" / origin (AHEX30) res (AHEX30).

FORMAT origin res (A15).

EXE. 


LIST CASES /FORMAT=NUM.