/* Program reads financial statements data */

libname lib1 "W:\Uudet_datat\FIRM_FSS";
libname lib100 "W:\Tutkimusprojektit\Kirjanpito\Dokumentaatio\JAR\Datat\";
run;

/* Years 1986 - 2019 */

data tilinpaatos_8619;
set lib1.tp8623;

YEAR = vuosi*1;

if 2019 >= year >= 1986;

if oik = 'ZZ' then delete;
if oik_vero = 'ZZ' then delete;

if syrtun = '' then delete;
if oik = 31 or oik_vero = 12;

if tol02 = '' and tol08 = '' then delete;
if tol02 = '99999' or tol08 = '00000' then delete;

INDUSTRY2_2 = substr (tol02,1,2); * 2-digit Standard Industrial Classification TOL 2008, which are based on the EU's classification of economic activities NACE;			

INDUSTRY2_3 = substr (tol02,1,3);
INDUSTRY2_4 = substr (tol02,1,4);
INDUSTRY2_5 = substr (tol02,1,5);
INDUSTRY2 = substr (tol08,1,2);				

 INDUSTRY_TIL = 0;
 if INDUSTRY2 = '01' then  INDUSTRY_TIL = 1;		* A;
 if INDUSTRY2 = '02' then  INDUSTRY_TIL = 1;
 if INDUSTRY2 = '03' then  INDUSTRY_TIL = 1;

 if INDUSTRY2_2 = '01' then  INDUSTRY_TIL = 1;
 if INDUSTRY2_2 = '02' then  INDUSTRY_TIL = 1;
 if INDUSTRY2_2 = '05' then  INDUSTRY_TIL = 1;

 if INDUSTRY2 = '05' then  INDUSTRY_TIL = 2;		* B;
 if INDUSTRY2 = '06' then  INDUSTRY_TIL = 2;
 if INDUSTRY2 = '07' then  INDUSTRY_TIL = 2;
 if INDUSTRY2 = '08' then  INDUSTRY_TIL = 2;
 if INDUSTRY2 = '09' then  INDUSTRY_TIL = 2;

 if INDUSTRY2_2 = '10' then  INDUSTRY_TIL = 2;
 if INDUSTRY2_2 = '11' then  INDUSTRY_TIL = 2;
 if INDUSTRY2_2 = '12' then  INDUSTRY_TIL = 2;
 if INDUSTRY2_2 = '13' then  INDUSTRY_TIL = 2;
 if INDUSTRY2_2 = '14' then  INDUSTRY_TIL = 2;
	
 if INDUSTRY2 = '10' then  INDUSTRY_TIL = 3;		* C;
 if INDUSTRY2 = '11' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '12' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '13' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '14' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '15' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '16' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '17' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '18' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '19' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '20' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '21' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '22' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '23' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '24' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '25' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '26' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '27' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '28' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '29' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '30' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '31' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '32' then  INDUSTRY_TIL = 3;
 if INDUSTRY2 = '33' then  INDUSTRY_TIL = 3;

 if INDUSTRY2_2 = '15' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '16' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '17' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '18' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '19' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '20' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '21' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '22' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '23' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '24' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '25' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '26' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '27' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '28' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '29' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '30' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '31' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '32' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '33' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '34' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '35' then  INDUSTRY_TIL = 3;
 if INDUSTRY2_2 = '36' then  INDUSTRY_TIL = 3;

 if INDUSTRY2 = '35' then  INDUSTRY_TIL = 4;		* D & E;
 if INDUSTRY2 = '36' then  INDUSTRY_TIL = 4;
 if INDUSTRY2 = '37' then  INDUSTRY_TIL = 4;
 if INDUSTRY2 = '38' then  INDUSTRY_TIL = 4;
 if INDUSTRY2 = '39' then  INDUSTRY_TIL = 4;

 if INDUSTRY2_2 = '37' then  INDUSTRY_TIL = 4;
 if INDUSTRY2_2 = '40' then  INDUSTRY_TIL = 4;
 if INDUSTRY2_2 = '41' then  INDUSTRY_TIL = 4;
 if INDUSTRY2_2 = '90' then  INDUSTRY_TIL = 4;

 if INDUSTRY2 = '41' then  INDUSTRY_TIL = 5;		* F;
 if INDUSTRY2 = '42' then  INDUSTRY_TIL = 5;
 if INDUSTRY2 = '43' then  INDUSTRY_TIL = 5;

 if INDUSTRY2_2 = '45' then  INDUSTRY_TIL = 5;
 if INDUSTRY2_4 = '7011' then  INDUSTRY_TIL = 5;

 if INDUSTRY2 = '45' then  INDUSTRY_TIL = 6;		* G;
 if INDUSTRY2 = '46' then  INDUSTRY_TIL = 6;
 if INDUSTRY2 = '47' then  INDUSTRY_TIL = 6;

 if INDUSTRY2_2 = '50' then  INDUSTRY_TIL = 6;
 if INDUSTRY2_2 = '51' then  INDUSTRY_TIL = 6;
 if INDUSTRY2_2 = '52' then  INDUSTRY_TIL = 6;

 if INDUSTRY2 = '49' then  INDUSTRY_TIL = 7;		* H;
 if INDUSTRY2 = '50' then  INDUSTRY_TIL = 7;
 if INDUSTRY2 = '51' then  INDUSTRY_TIL = 7;
 if INDUSTRY2 = '52' then  INDUSTRY_TIL = 7;
 if INDUSTRY2 = '53' then  INDUSTRY_TIL = 7;

 if INDUSTRY2_2 = '60' then  INDUSTRY_TIL = 7;
 if INDUSTRY2_2 = '61' then  INDUSTRY_TIL = 7;
 if INDUSTRY2_2 = '62' then  INDUSTRY_TIL = 7;
 if INDUSTRY2_2 = '63' then  INDUSTRY_TIL = 7;
 if INDUSTRY2_2 = '64' then  INDUSTRY_TIL = 7;

 if INDUSTRY2 = '55' then  INDUSTRY_TIL = 8;		* I;
 if INDUSTRY2 = '56' then  INDUSTRY_TIL = 8;

 if INDUSTRY2_2 = '55' then  INDUSTRY_TIL = 8;

 if INDUSTRY2 = '58' then  INDUSTRY_TIL = 9;		* J;
 if INDUSTRY2 = '59' then  INDUSTRY_TIL = 9;
 if INDUSTRY2 = '60' then  INDUSTRY_TIL = 9;
 if INDUSTRY2 = '61' then  INDUSTRY_TIL = 9;
 if INDUSTRY2 = '62' then  INDUSTRY_TIL = 9;
 if INDUSTRY2 = '63' then  INDUSTRY_TIL = 9;

 if INDUSTRY2_2 = '72' then  INDUSTRY_TIL = 9;
 if INDUSTRY2_3 = '221' then  INDUSTRY_TIL = 9;
 if INDUSTRY2_3 = '642' then  INDUSTRY_TIL = 9;
 if INDUSTRY2_3 = '921' then  INDUSTRY_TIL = 9;
 if INDUSTRY2_3 = '922' then  INDUSTRY_TIL = 9;
 if INDUSTRY2_3 = '924' then  INDUSTRY_TIL = 9;

 if INDUSTRY2 = '64' then  INDUSTRY_TIL = 10;		* K;
 if INDUSTRY2 = '65' then  INDUSTRY_TIL = 10;
 if INDUSTRY2 = '66' then  INDUSTRY_TIL = 10;

 if INDUSTRY2_2 = '65' then  INDUSTRY_TIL = 10;
 if INDUSTRY2_2 = '66' then  INDUSTRY_TIL = 10;
 if INDUSTRY2_2 = '67' then  INDUSTRY_TIL = 10;

 if INDUSTRY2 = '68' then  INDUSTRY_TIL = 11;		* L;

 if INDUSTRY2_2 = '70' and INDUSTRY2_4 ^= '7011' then  INDUSTRY_TIL = 11;
 if INDUSTRY2_2 = '70' and INDUSTRY2_4 ^= '7011' then  INDUSTRY_TIL = 11;
 if INDUSTRY2_2 = '70' and INDUSTRY2_4 ^= '7032' then  INDUSTRY_TIL = 11;

 if INDUSTRY2 = '69' then  INDUSTRY_TIL = 12;		* M;
 if INDUSTRY2 = '70' then  INDUSTRY_TIL = 12;
 if INDUSTRY2 = '71' then  INDUSTRY_TIL = 12;
 if INDUSTRY2 = '72' then  INDUSTRY_TIL = 12;
 if INDUSTRY2 = '73' then  INDUSTRY_TIL = 12;
 if INDUSTRY2 = '74' then  INDUSTRY_TIL = 12;
 if INDUSTRY2 = '75' then  INDUSTRY_TIL = 12;

 if INDUSTRY2_2 = '73' then  INDUSTRY_TIL = 12;
 if INDUSTRY2_3 = '741' then  INDUSTRY_TIL = 12;
 if INDUSTRY2_3 = '742' then  INDUSTRY_TIL = 12;
 if INDUSTRY2_3 = '743' then  INDUSTRY_TIL = 12;
 if INDUSTRY2_3 = '744' then  INDUSTRY_TIL = 12;
 if INDUSTRY2_4 = '7481' then  INDUSTRY_TIL = 12;
 if INDUSTRY2_3 = '852' then  INDUSTRY_TIL = 12;

 if INDUSTRY2 = '77' then  INDUSTRY_TIL = 13;		* N;
 if INDUSTRY2 = '78' then  INDUSTRY_TIL = 13;
 if INDUSTRY2 = '79' then  INDUSTRY_TIL = 13;
 if INDUSTRY2 = '80' then  INDUSTRY_TIL = 13;
 if INDUSTRY2 = '81' then  INDUSTRY_TIL = 13;
 if INDUSTRY2 = '82' then  INDUSTRY_TIL = 13;

 if INDUSTRY2_2 = '71' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_3 = '633' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_3 = '745' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_3 = '746' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_3 = '747' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_3 = '748' and INDUSTRY2_4 ^= '7481' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_4 = '7032' then  INDUSTRY_TIL = 13;
 if INDUSTRY2_5 = '90031' then  INDUSTRY_TIL = 13;

 if INDUSTRY2 = '84' then  INDUSTRY_TIL = 14;		* O and P;
 if INDUSTRY2 = '85' then  INDUSTRY_TIL = 14;

 if INDUSTRY2_2 = '75' then  INDUSTRY_TIL = 14;	
 if INDUSTRY2_2 = '80' then  INDUSTRY_TIL = 14;	

 if INDUSTRY2 = '86' then  INDUSTRY_TIL = 15;		* Q;
 if INDUSTRY2 = '87' then  INDUSTRY_TIL = 15;		
 if INDUSTRY2 = '88' then  INDUSTRY_TIL = 15;

 if INDUSTRY2_2 = '85' and INDUSTRY2_3 ^= '852' then  INDUSTRY_TIL = 15;

 if INDUSTRY2 = '90' then  INDUSTRY_TIL = 16;		* R;
 if INDUSTRY2 = '91' then  INDUSTRY_TIL = 16;
 if INDUSTRY2 = '92' then  INDUSTRY_TIL = 16;
 if INDUSTRY2 = '93' then  INDUSTRY_TIL = 16;

 if INDUSTRY2_3 = '923' then  INDUSTRY_TIL = 16;
 if INDUSTRY2_3 = '925' then  INDUSTRY_TIL = 16;
 if INDUSTRY2_3 = '926' then  INDUSTRY_TIL = 16;
 if INDUSTRY2_3 = '927' then  INDUSTRY_TIL = 16;	

 if INDUSTRY2 = '94' then  INDUSTRY_TIL = 17;		* S, T, and U;
 if INDUSTRY2 = '95' then  INDUSTRY_TIL = 17;		
 if INDUSTRY2 = '96' then  INDUSTRY_TIL = 17;	
 if INDUSTRY2 = '97' then  INDUSTRY_TIL = 17;	
 if INDUSTRY2 = '98' then  INDUSTRY_TIL = 17;		
 if INDUSTRY2 = '99' then  INDUSTRY_TIL = 17;

 if INDUSTRY2_2 = '91' then  INDUSTRY_TIL = 17;	
 if INDUSTRY2_3 = '527' then  INDUSTRY_TIL = 17;
 if INDUSTRY2_3 = '930' then  INDUSTRY_TIL = 17;
 if INDUSTRY2_3 = '361' then  INDUSTRY_TIL = 17;

HIGH_TECH_INDUSTRY = 0;
if INDUSTRY2 = '58' or INDUSTRY2 = '59' or INDUSTRY2 = '60' or INDUSTRY2 = '61' or INDUSTRY2 = '62' or INDUSTRY2 = '63' or INDUSTRY2 = '69' or INDUSTRY2 = '70'
or INDUSTRY2 = '71' or INDUSTRY2 = '72' or INDUSTRY2 = '73' or INDUSTRY2 = '74' or INDUSTRY2 = '75' or INDUSTRY2 = '21' or INDUSTRY2 = '26' or INDUSTRY2 = '27'
or INDUSTRY2 = '28' or INDUSTRY2 = '29' or INDUSTRY2 = '30' then HIGH_TECH_INDUSTRY = 1;

rename syrtun = FIRM;

run;

* Saves data;

data lib100.tilinpaatokset_kaikki_080622;
set tilinpaatos_8619;
run;


