title: How to convert a SAS retain in Teradata sql?
body: <p>I'm trying to convert SAS code into Teradata and I'm struggling how to convert the code below. The issue is how to convert the retain statement into sql.</p>
  
  <p>** Datastep code</p>
  
  <pre><code>data test2;
    set test1;
    by name_id;
    format counter 8.0;
    retain counter year_counter;
    if first.name_id then do;
      counter = month_start;
      year_counter=year_start;
    end;
    else counter=counter+1;
    if(counter=13) then do;
      counter=1;
      year_counter=year_counter+1;
    end;
    mmyy_counter=compress(counter|"/"|year_counter);
    mmyy=compress(month|"/"|year);
  run;
  </code></pre>
  
  <p>**Data</p>
  
  <pre><code>name_id  month_start  month_year
  12131as  07           2010
  12132ab  02           2003
  </code></pre>
  
  <p>**My thoughts</p>
  
  <p>I was thinking of putting this in a procedure, although I'm not sure how.
  Another possibility is to use row_number, but again I am not sure how to start.</p>