Write special ASCII file
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 | /* QUESTION: In order to export to a given software, I need to convert the SPSS data file to an ASCII file where each col is separated by one comma and one blank. In addition first line must contain the Buoy_ID last line must contain the word END*/. * ANSWER by rlevesque@videotron.ca. DATA LIST LIST /Buoy_ID Buoy_Obs Lat Long. BEGIN DATA 1 1 1 1.234 1 2 2 22.3561 1 3 3 3 2215 10.2521 4 4 2215 2 5 5 2215 3 625.3265 6 2215 4 7 7 END DATA. LIST. * If file is not already sorted by Buoy_ID, remove the * at the beginning of next line. *SORT CASES BY Buoy_ID. MATCH FILES FILE=* /BY Buoy_ID /FIRST=first /LAST=last. STRING outvar(A80). * Use whatever number you need instead of 10, 8 and 4 in the next line. COMPUTE outvar=CONCAT(LTRIM(STRING(Buoy_Obs,F10.0)),", ",LTRIM(RTRIM(STRING(Lat,F8.4))),", ",LTRIM(STRING(Long,F8.4))). VECTOR d(3F8.0). DO IF first. WRITE OUTFILE='c:\\temp\\tmp.txt' TABLE/ Buoy_ID. WRITE OUTFILE='c:\\temp\\tmp.txt' TABLE/ outvar. ELSE IF ~last. WRITE OUTFILE='c:\\temp\\tmp.txt' TABLE/ outvar. ELSE IF last. WRITE OUTFILE='c:\\temp\\tmp.txt' TABLE/ outvar. WRITE OUTFILE='c:\\temp\\tmp.txt' TABLE/ "End". END IF. EXECUTE. |
Related pages
...