Read text file where n columns are to be ignored
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 | * Read text files where n columns of data are to be ignored. * (n is a variable). *(Q) >I am writing a read-in >program that will be used repeatedly an many data sets. They are all >identical, except that the initial column of useable data varies. >From that point out to the right, all of the files will be the same. > >I'd like to set up the read in program where the users will just have >to enter this starting position once, and it will be automitically >placed in the rest of the data list command. This poses two problems: >a) I can't get the number in the first time and b) how can I >manipulate it to "add" columns for the rest of the data set? If I >could just get something like the program below to work, I believe >that I can modify if from there. > >I'm trying to feed the '6' from the define line into the data list >line. Then, I'd like to add on to it for the next part. Obviously, >this doesn't work. I'm very open to any suggestions. > > >*********** Pathetic excuse for syntax follows. >new file. >define !start ()'6'!enddefine. >DATA LIST /Age 1-2 SEX 4 (A) bday !start - (!start + 5). >BEGIN DATA >28 M 25000 >26 F 28500 >25 M 30000 >END DATA. >LIST. *(A) Posted to SPSS newsgroup by Raynald Levesque on 2002/05/02. * http://pages.infinit.net/rlevesqu/index.htm. The following does what you are asking: new file. set mprint=no. define !dlist(col=!TOKENS(1)) !LET !endcol=!LENGTH(!CONCAT(!BLANK(!col),!BLANK(5))) DATA LIST /Age 1-2 SEX 4 (A) bday !col - !endcol. !enddefine. set mprint=yes. !dlist col=6. BEGIN DATA 28 M 25000 26 F 28500 25 M 30000 END DATA. LIST. ***********. HOWEVER this is going to be cumbersome if you have many variables after bday. I think the following solution is EASIER: DATA LIST FIXED /col1 TO col20 1-20 (A). BEGIN DATA 28 M xxx25000 26 F xxx28500 25 M xxx30000 END DATA. LIST. * The 9 in next line would be changed as needed. WRITE OUTFILE='c:\\temp\\data.txt' /col1 TO col5 col9 TO col20. EXECUTE. * The next line is always the same. DATA LIST FILE='c:\\temp\\data.txt' FIXED /Age 1-2 SEX 4 (A) bday 6 - 11. LIST. |
Related pages
...