title: SPSS 22: looping through 4000 text files and parsing data out of it
body: <p>Unfortunately, Stata does does not recognize UTF8/Unicode. Fortunately, SPSS 22 does! I'm trying to parse specific rows containing variables with weird characters out of +/- 4000 .txt files. Thus far, I have only managed to do it with only 1 .txt file with the following code:</p>
  
  <pre><code>* First, get the text files.
  GET DATA  /TYPE=TXT 
  /FILE="\my\path\20001_friends.txt" 
  /ENCODING='UTF8' 
  /DELCASE=LINE 
  /DELIMITERS=" " 
  /ARRANGEMENT=DELIMITED 
  /FIRSTCASE=1 
  /IMPORTCASE=ALL 
  /VARIABLES= 
  V1 A2082 
  V2 A2118 
  V3 A27 
  V4 A36 
  V5 A113 
  V6 A54 
  V7 A49 
  V8 A47 
  V9 A78 
  V10 A109 
  V11 A33 
  V12 A15 
  V13 A81 
  V14 A4 
  V15 A21 
  V16 A7. 
  CACHE. 
  EXECUTE. 
  DATASET NAME DataSet1 WINDOW=FRONT.
  
  * Second, compute conditional upon Vriend = 1.
  COMPUTE x = 0.
  IF (V5 = "Vriend") x = 1.
  COMPUTE y = 1.
  EXECUTE.
  
  * Third, get every observation after Vriend.
  IF y ~= lag(x) z = 0.
  IF y = lag(x) z = 1.
  EXECUTE.
  
  * Fourth, select only the names.
  SELECT IF z = 1.
  EXECUTE.
  </code></pre>
  
  <p>I want to do this for +/- 4000 of files and end with an appended list of rows of all the rows I parsed from this text files (while deleting the rest). Also, the text files go from 20001_names.txt to 36872_names.txt, so not every identifier is available. e.g., 20002_names.txt might be missing, whilst 20003_names.txt might exist. I also want to construct a variable indicating the identifier from which the row came from (e.g., id = 20001 for all the rows parsed from the first file). </p>