title: SPSS Macro: compute by variable name
body: <p>I don't think SPSS macros can return values, so instead of assigning a value like <code>VIXL3 = !getLastAvail target=VIX level=3</code> I figured I need to do something like this:</p>
  
  <pre><code>/* computes last available entry of target at given level */
  define !compLastAvail(name !Tokens(1) /target !Tokens(1) /level !Tokens(1))
     compute tmpid= $casenum.
     dataset copy tmpset1.
     select if not miss(!target).
     compute !name= lag(!target, !level).
     match files /file= * /file= tmpset1 /by tmpid.
     exec.
     delete variables tmpid.
     dataset close tmpset1.
  !enddefine.
  
  /* compute last values */
  
  !compLastAvail name="VIXCL3" target=VIXC level=3.
  </code></pre>
  
  <p>The <code>compute !name = ...</code>is where the problem is.</p>
  
  <p>How should this be done properly? The above returns:</p>
  
  <pre><code>&gt;Error # 4285 in column 9.  Text: VIXCL3
  &gt;Incorrect variable name: either the name is more than 64 characters, or it is
  &gt;not defined by a previous command.
  &gt;Execution of this command stops.
  </code></pre>