mardi 3 novembre 2020

SAS do loop except some variable value question

I am currently learning SAS and I have this code: saving 2000 each month(capital) with 0.3 interest/ year until I reach 50,000 $.

data retire;
  earned=0;
  year=0;
  do until (capital>=50000);
    year+1;

    do month=1 to 12 until (capital >=50000);
      capital+2000;
      interest=capital*(0.3/12);
      capital+interest;
      earned+interest;
      output;
    end;
  end;
run;

Now I want to change capital of month 12 each year by 1000(save $2000 every month except December, which saving just $1000). But I can't find how to edit only month 12's capital value. I tried if then statement and when statement but it keeps making an error. I have no idea what I am doing wrong, is there other way to do this than if then statement?

data retire1;
  earned=0;
  year=0;
  do until (capital>=50000);
    year+1;

    do month=1 to 12 until (capital >=50000);
      if month <12 then capital+2000;
      in month =12 then capital+1000;
      interest=capital*(0.3/12);
      capital+interest;
      earned+interest;
      output;
    end;
  end;
run;

Aucun commentaire:

Enregistrer un commentaire