title: changing date formats to YYMMDD8. in SAS for date calculations
body: <p>I've got a date variable in my dataset(currently numeric) that has three types of dates:</p>
  
  <ol>
  <li><p>just the year (yyyy)</p></li>
  <li><p>year/month (yyyymm)</p></li>
  <li><p>year/month/date (yyyymmdd)</p></li>
  </ol>
  
  <p>I'm trying to convert the ones with just the year to January 1st, and convert the ones with year/month to the first of the month so that I can subtract the dates from another date variable in my dataset that has all the dates in yymmdd8 format (same as #3). I tried this in the data step and it's not working:</p>
  
  <pre><code>if length(Date)=4 then DateF=mdy(1,1,substr(Date,1,4));  
  if length(Date)=6 then DateF=mdy(substr(Date,5,2),1,substr(Date,1,4));  
  if length(Date)=8 then DateF=mdy(substr(Date,5,2),substr(Date,7,2),substr(Date,1,4));  
  Date2=input(put(DateF,8.),YYMMDD8.);  
  format Date2 YYMMDD8.;
  </code></pre>
  
  <p>Can someone tell me what's wrong with my code? Thanks!</p>