/* Program reads income data obtained from tax filings */

libname lib24 "W:\Uudet_datat\U0599_9_toim\";
libname lib100 "W:\Tutkimusprojektit\Kirjanpito\Dokumentaatio\JAR\Datat\";
run; 

data aaa;
 set lib24.henkiloverotus_9_s;					
 YEAR = vuosi;
 ID = shnro;

 keep YEAR ID svatva svatv svatvp;

run;

proc sort nodupkey data = aaa;					
 by ID YEAR;
run; 

data bbb;
 set aaa; 

 SALARYTOTAL = svatva;						* Salaryincome, total (= SALARYINCOME + PENSIONINCOME + OTHERSALINCOME);
 LN_SALARYTOTAL = log(SALARYTOTAL+1);

 CAPITALTOTAL = svatvp;						* Capital income, total (= DIVIDENDINCOME + RENTALINCOME + OTHERCAPINCOME);   
 LN_CAPITALTOTAL = log(CAPITALTOTAL+1);

 TOTALINCOME = svatv;						* Total income (= SALARYTOTAL + CAPITALTOTAL);
 LN_TOTALINCOME = log(TOTALINCOME+1);

run;

proc sort nodupkey data = bbb;
 by ID YEAR;
run;

* Saves data;

data lib100.henkiloverotus_220925;
 set bbb;

if SALARYTOTAL = . then SALARYTOTAL = 0;
if TOTALINCOME = . then TOTALINCOME = 0;
if LN_SALARYTOTAL = . then LN_SALARYTOTAL = 0;
if LN_TOTALINCOME = . then LN_TOTALINCOME = 0;
if CAPITALTOTAL = . then CAPITALTOTAL = 0;
if LN_CAPITALTOTAL = . then LN_CAPITALTOTAL = 0;

 keep ID YEAR SALARYTOTAL TOTALINCOME LN_SALARYTOTAL LN_TOTALINCOME CAPITALTOTAL LN_CAPITALTOTAL;
run; 






