*rsubmit;


*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
* Place all general macros into this file;
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
%include 'modules/nwords.sas';
%include 'modules/quarterize.sas';

/********************************************************************************


	Macro: 		get_returns
	Purpose: 	to obtain returns over a specified period relative to a certain date;
	Version:	1.0.		7/6/21;
	
	Author:		Jared Flake

--------------------------------------------

	Required INPUT parameters:
		dsetin			-	input dataset name
		dsetout			-	output dataset name
		mkt				-	market return variable used to calculate abnormal returns (i.e., vwretd, ewretd, etc.)
		n_before		-	the number of periods to include prior to the event date
		n_after			-	the number of periods to include after the event date
		event_date		-	the date of the event of interest (e.g., rdq for EA)

	Optional INPUT parameters:
		freq			-	frequency of return calculation (dsf, msf)
							- default = dsf
		car_name		-	variable name prefix for the cumulative abnormal return
							- default = car
		bhar_name		-	variable name prefix for the buy and hold abnormal return
							- default = bhar
		n_name			-	variable name prefix for the number of observations used in return calculations
							- default = n

********************************************************************************/
* Get CAR Macro;

*%get_returns(merged_reports2,merged_reports4,vwretd,
	dsf,0,1,anndats);

%macro get_returns(dsetin=,dsetout=,mkt=,freq=,n_before=,n_after=,event_date=,car_name=car,bhar_name=bhar,n_name=n,std_name=stdev);
%if &freq = dsf %then %do;
	%let freq2 = dsi;
	%let interval = 'weekday';
%end;
%if &freq = msf %then %do;
	%let freq2 = msi;
	%let inverval = 'month';
%end;

proc sort data = &dsetin out = temp (keep = permno &event_date); by permno &event_date;
run;

proc sql;
	create table rets as select
	a.*, b.date, b.ret
	from &dsetin as a left join crsp.&freq as b
	on a.permno = b.permno
	and intnx(&interval,a.&event_date,-&n_before) le b.date le intnx(&interval,a.&event_date,&n_after);
quit;

proc sql;
	create table rets as select
	a.*, b.&mkt
	from rets as a left join crsp.&freq2 as b
	on a.date = b.date;
quit;

proc sort data = rets nodupkey; by permno &event_date date;
run;

proc sql;
	create table rets2 as select distinct
	permno, &event_date,
					sum(ret-vwretd) as &car_name._M&n_before.to_P&n_after,
					exp(sum(log(1+ret))) - exp(sum(log(1+vwretd))) as &bhar_name._M&n_before.to_P&n_after,
					count(ret) as &n_name._M&n_before.to_P&n_after,
					std(ret) as &std_name._M&n_before.to_P&n_after
	from rets group by permno, &event_date
	order by permno, &event_date;
quit;

proc sql;
	create table &dsetout as select 
	a.*, b.&car_name._M&n_before.to_P&n_after, b.&bhar_name._M&n_before.to_P&n_after, b.&n_name._M&n_before.to_P&n_after, b.&std_name._M&n_before.to_P&n_after
	from &dsetin as a left join rets2 as b
	on a.permno = b.permno
	and a.&event_date = b.&event_date;
quit;
%mend get_returns;

%macro CAR_EVOLUTION(in=,out=,event_date=,freq=dsf,start=,end=);
%if &freq = dsf %then %do;
	%let pdicity = 'weekday';
	%let freq2 = dsi;
%end;
%if &freq = msf %then %do;
	%let pdicity = 'month';
	%let freq2 = msi;
%end;

proc sql;
	create table rets as select
	a.*, b.date, b.ret
	from &in as a left join crsp.&freq as b
	on a.permno = b.permno
	and intnx(&pdicity,a.&event_date,&start) le b.date le intnx(&pdicity,a.&event_date,&end);
quit;

proc sql;
	create table rets as select
	a.*, b.vwretd
	from rets as a left join crsp.&freq2 as b
	on a.date = b.date
	order by permno, &event_date, date;
quit;

proc sort data = rets nodupkey; by permno &event_date date;
run;

data returns; set rets; by permno &event_date date;
t = intck(&pdicity,&event_date,date);
abret = ret - vwretd;
lnret = log(1+ret);
lnvwret = log(1+vwretd);
retain car _lnret _lnvwret n;
if first.&event_date then do 
	_lnret = lnret;
	_lnvwret = lnvwret;
	car = abret;
	bhar = exp(lnret) - exp(lnvwret);
	n = 1;
end;
else do;
	_lnret + lnret;
	_lnvwret + lnvwret;
	car + abret;
	bhar = exp(_lnret) - exp(_lnvwret);
	n+1;
end;
drop abret _lnret _lnvwret ret vwretd lnret lnvwret; 
run;

proc sort data = returns; by permno &event_date descending date;
run;

data returns2; set returns; by permno &event_date descending date;
retain max_car max_bhar;
if first.disclosure_date then do;
	max_car = car;
	max_bhar = bhar;
end;
run;

data returns3; set returns2;
CAR_frac = car/max_car;
bhar_frac = bhar/max_bhar;
run;

proc sort data = returns3 out = &out; by permno &event_date date;
run;

proc download data = returns3 out = returns;
run;
%mend;



/********************************************************************************


	Macro: 		ttest
	Purpose: 	to make a concise ttest table;
	Version:	2.0.		8/9/12;
	
	Author:		Ed deHaan		
				staff.washington.edu/edehaan

--------------------------------------------

	Required INPUT parameters:
		infile			-	input dataset name
		class			-	ttest class variable.  must be an indicator - missing values are okay;
		var				-	list of variables.  do not separate with commas
	
	Optional INPUT parameters:
		output			-	name of table with final results.
							- default = results
		probf_sig		-	significance level for determining whether the classes have unequal variance
							- default = 0.10
		show_class_n	-	option to include number of observations for each class;
							- default = no;
		show_variances	-	option to include whether variances are equal or unequal;
							- default = yes;

********************************************************************************/




%macro ttest( infile, class, var, output = results, probf_sig = 0.1, show_class_n = no, show_variances = yes);

	%put=  '******************** T-TEST MACRO **********************';

	ods listing close;
	proc ttest data=&infile	nobyvar;
		class &class;
		var &var;
		ods output 	ttests = tstats
					statistics = stats
					'equality of variances' = eq;
	run;
	ods output close;
	ods listing;


	*put stats into useable form;
	data class1 (keep= n_&class mean_&class variable) class0 (keep= n_non&class mean_non&class variable);
		set stats;
		if(class = '0') then do;
			n_non&class		= n;
			mean_non&class 	= mean;
			output class0;
		end;
		
		if(class = '1') then do;
			n_&class		= n;
			mean_&class 	= mean;
			output class1;
		end;
	run;
	
	proc sql;
		create 	table stats as
		select	a.variable, a.n_non&class,b.n_&class, (a.n_non&class + b.n_&class) as n_total, 
				a.mean_non&class, b.mean_&class, (b.mean_&class - a.mean_non&class) as difference
		from	class0 as a left join class1 as b
		on		a.variable = b.variable;
	quit;	
	
	
	* bring in equality of variables to tstats;
	proc sql;
		create	table tstats2 as
		select 	a.*, b.probf as prob_variance
		from	tstats as a left join eq as b
		on		a.variable = b.variable;
	quit;
	
	data tstats2;
		set tstats2;
		if(prob_variance le &probf_sig and variances = 'Unequal') then output;
		if(prob_variance > &probf_sig and variances = 'Equal') then output;
	run;
	

	*bring back together;
	proc sql;
		create 	table &output as
		select	a.*, b.variances, b.tvalue, b.probt
		from	stats as a left join tstats2 as b
		on		a.variable = b.variable
		order	by variable;
	quit;
	

	*include option to not display class_n;
	%if(%lowcase(&show_class_n) = no) %then %do;
		data &output;
			set &output;
			drop n_non&class n_&class;
		run;
	%end;


	*include option to not display variances type;
	%if(%lowcase(&show_variances) ne yes) %then %do;
		data &output;
			set &output;
			drop variances;
		run;
	%end;


	*output table;	
	title5		" ****** T-Test Output: &class versus non&class ******* ";
	proc print data=&output;
	run;
	title5;
	

%mend ttest;



*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
* Correlation Table:  Pearson (above), Spearman (below);
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro corrps(dset=,vars=);

%let i=1;
%do %until (%SCAN(&vars,&i,%STR( ))=);
    %let v&i=%SCAN(&vars,&i,%STR( ));
    %let i=%EVAL(&i+1);
%end;
%let nvars = %eval(&i - 1);

    %macro cor_rep(sta,fin);
    %do i=&sta %to &fin;
        , (xp.&&v&i + xs.&&v&i) as &&v&i
    %end;
    %mend;

proc corr data=&dset outp=xp outs=xs;
    var &vars;
    run;

data xp;
    set xp;
    where _TYPE_ = 'CORR';
    array vars {*} &vars;
    do i=1 to (_N_ - 1);
        vars(i) = 0;
    end;
    run;

data xs;
    set xs;
    where _TYPE_ = 'CORR';
    array vars {*} &vars;
    do i=_N_ to &nvars;
        vars(i) = 0;
    end;
    run;

proc sql;
    create table xps as
    select xp._NAME_ as Variable %cor_rep(1,&nvars)
    from xp, xs where (xp._NAME_ = xs._NAME_);
    quit;

proc print data=xps noobs;
    title2 'Pearson (above) / Spearman (below) Correlations';
    run;

title2;

%mend;



*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
* Descriptive Statistics by groups.  You can group by more than one variable, just separate by spaces;
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro descr_by(dset=,byvar=,vars=,stats=n mean min p1 p25 p50 p75 p99 max);

%let j=1;
%do %until ( %scan(&vars,&j)= );
  %let var&j = %scan(&vars,&j);
  %let j=%EVAL(&j+1);
%end;

proc sort data=&dset out=xtemp;
    by &byvar;
    run;

ods listing close;
proc means data=xtemp &stats;
    by &byvar;
    var &vars;
    ods output Summary = xout;
    run;
ods listing;

%do k = 1 %to %EVAL(&j-1);

  %let base = &&var&k;

  proc print data=xout noobs;
      var &byvar &base._:;
      run;

%end;
%mend descr_by;


*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
* Make dummy variables
* Pre = prefix for dummy variable names
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro make_dummies(dset=,var=,pre=d_);

proc sql noprint;
    select n(&var) into :n from (select distinct &var from &dset);
    %let n = %trim(&n);
    select xvar into :xvar1 - :xvar&n from (select distinct &var as xvar from &dset);
    quit;

data &dset;
    set &dset;
    %do i = 1 %to &n;
        if &var = "&&xvar&i" then &pre&&xvar&i = 1; else &pre&&xvar&i = 0;
    %end;
    run;

%mend make_dummies;



*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
/* ARGUMENTS:  		1) data: input dataset containing variables that will be win/trunc.	  */
/*					2) out: output dataset (leave blank to overwrite data)			  */
/*					3) BYVAR: variable(s) used to form groups (type 'none' for total sample)  */
/*					4) VARS: variable(s) that will be winsorized/truncated					  */
/*					5) TYPE: = W to winsorize and = T (or anything else) to truncate		  */
/*					6) PCTL = percentile points (in ascending order) to truncate/winsorize	  */
/*						      values.  Default is 1st and 99th percentiles.					  */
/* DESCRIPTION:		This macro is capable of both truncating and winsorizing one or multiple  */
/*					variables.  Truncated values are replaced with a missing observation	  */
/*					rather than deleting the observation.  This gives the user more control   */
/*					over the resulting dataset.												  */
/* EXAMPLE(S):		1) %WT(data = mydata, out = mydata2, byvar = year,  */
/*					        vars = assets earnings, type = W, pctl = 0 98)					  */
/*						==> Winsorizes by year at 98% and puts resulting dataset into mydata2 */
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro WT(data=_last_, out=, byvar=none, vars=, type = W, pctl = 1 99, drop= N);

	%if &out = %then %let out = &data;
    
	%let varLow=;
	%let varHigh=;
	%let xn=1;

	%do %until (%scan(&vars,&xn)= );
    	%let token = %scan(&vars,&xn);
    	%let varLow = &varLow &token.Low;
    	%let varHigh = &varHigh &token.High;
    	%let xn = %EVAL(&xn + 1);
	%end;

	%let xn = %eval(&xn-1);

	data xtemp;
   	 	set &data;

	%let dropvar = ;
	%if &byvar = none %then %do;
		data xtemp;
        	set xtemp;
        	xbyvar = 1;

    	%let byvar = xbyvar;
    	%let dropvar = xbyvar;
	%end;

	proc sort data = xtemp;
   		by &byvar;

	/*compute percentage cutoff values*/
	proc univariate data = xtemp noprint;
    	by &byvar;
    	var &vars;
    	output out = xtemp_pctl PCTLPTS = &pctl PCTLPRE = &vars PCTLNAME = Low High;

	data &out;
    	merge xtemp xtemp_pctl; /*merge percentage cutoff values into main dataset*/
    	by &byvar;
    	array trimvars{&xn} &vars;
    	array trimvarl{&xn} &varLow;
    	array trimvarh{&xn} &varHigh;

    	do xi = 1 to dim(trimvars);
			/*winsorize variables*/
        	%if &type = W %then %do;
            	if trimvars{xi} ne . then do;
              		if (trimvars{xi} < trimvarl{xi}) then trimvars{xi} = trimvarl{xi};
              		if (trimvars{xi} > trimvarh{xi}) then trimvars{xi} = trimvarh{xi};
            	end;
        	%end;
			/*truncate variables*/
        	%else %do;
            	if trimvars{xi} ne . then do;
              		if (trimvars{xi} < trimvarl{xi}) then trimvars{xi} = .T;
              		if (trimvars{xi} > trimvarh{xi}) then trimvars{xi} = .T;
            	end;
        	%end;

			%if &drop = Y %then %do;
			   if trimvars{xi} = .T then delete;
			%end;

		end;
    	drop &varLow &varHigh &dropvar xi;

	/*delete temporary datasets created during macro execution*/
	proc datasets library=work nolist;
		delete xtemp xtemp_pctl; quit; run;

%mend;




*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
*CREATES FAMA-FRENCH 17 INDUSTRY CLASSIFICATIONS
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro ff17(data=,newvarname=industry,sic=sic,out=&data);

data &out;
    set &data;
    &newvarname = 17;
if	100	<=	&sic	<=	199	then	&newvarname	=	17	;
else	if	200	<=	&sic	<=	299	then	&newvarname	=	1	;
else	if	700	<=	&sic	<=	799	then	&newvarname	=	1	;
else	if	900	<=	&sic	<=	999	then	&newvarname	=	1	;
else	if	2000	<=	&sic	<=	2009	then	&newvarname	=	1	;
else	if	2010	<=	&sic	<=	2019	then	&newvarname	=	1	;
else	if	2020	<=	&sic	<=	2029	then	&newvarname	=	1	;
else	if	2030	<=	&sic	<=	2039	then	&newvarname	=	1	;
else	if	2040	<=	&sic	<=	2046	then	&newvarname	=	1	;
else	if	2047	<=	&sic	<=	2047	then	&newvarname	=	1	;
else	if	2048	<=	&sic	<=	2048	then	&newvarname	=	1	;
else	if	2050	<=	&sic	<=	2059	then	&newvarname	=	1	;
else	if	2060	<=	&sic	<=	2063	then	&newvarname	=	1	;
else	if	2064	<=	&sic	<=	2068	then	&newvarname	=	1	;
else	if	2070	<=	&sic	<=	2079	then	&newvarname	=	1	;
else	if	2080	<=	&sic	<=	2080	then	&newvarname	=	1	;
else	if	2082	<=	&sic	<=	2082	then	&newvarname	=	1	;
else	if	2083	<=	&sic	<=	2083	then	&newvarname	=	1	;
else	if	2084	<=	&sic	<=	2084	then	&newvarname	=	1	;
else	if	2085	<=	&sic	<=	2085	then	&newvarname	=	1	;
else	if	2086	<=	&sic	<=	2086	then	&newvarname	=	1	;
else	if	2087	<=	&sic	<=	2087	then	&newvarname	=	1	;
else	if	2090	<=	&sic	<=	2092	then	&newvarname	=	1	;
else	if	2095	<=	&sic	<=	2095	then	&newvarname	=	1	;
else	if	2096	<=	&sic	<=	2096	then	&newvarname	=	1	;
else	if	2097	<=	&sic	<=	2097	then	&newvarname	=	1	;
else	if	2098	<=	&sic	<=	2099	then	&newvarname	=	1	;
else	if	5140	<=	&sic	<=	5149	then	&newvarname	=	1	;
else	if	5150	<=	&sic	<=	5159	then	&newvarname	=	1	;
else	if	5180	<=	&sic	<=	5182	then	&newvarname	=	1	;
else	if	5191	<=	&sic	<=	5191	then	&newvarname	=	1	;
else	if	1000	<=	&sic	<=	1009	then	&newvarname	=	2	;
else	if	1010	<=	&sic	<=	1019	then	&newvarname	=	2	;
else	if	1020	<=	&sic	<=	1029	then	&newvarname	=	2	;
else	if	1030	<=	&sic	<=	1039	then	&newvarname	=	2	;
else	if	1040	<=	&sic	<=	1049	then	&newvarname	=	2	;
else	if	1060	<=	&sic	<=	1069	then	&newvarname	=	2	;
else	if	1080	<=	&sic	<=	1089	then	&newvarname	=	2	;
else	if	1090	<=	&sic	<=	1099	then	&newvarname	=	2	;
else	if	1200	<=	&sic	<=	1299	then	&newvarname	=	2	;
else	if	1400	<=	&sic	<=	1499	then	&newvarname	=	2	;
else	if	5050	<=	&sic	<=	5052	then	&newvarname	=	2	;
else	if	1300	<=	&sic	<=	1300	then	&newvarname	=	3	;
else	if	1310	<=	&sic	<=	1319	then	&newvarname	=	3	;
else	if	1320	<=	&sic	<=	1329	then	&newvarname	=	3	;
else	if	1380	<=	&sic	<=	1380	then	&newvarname	=	3	;
else	if	1381	<=	&sic	<=	1381	then	&newvarname	=	3	;
else	if	1382	<=	&sic	<=	1382	then	&newvarname	=	3	;
else	if	1389	<=	&sic	<=	1389	then	&newvarname	=	3	;
else	if	2900	<=	&sic	<=	2912	then	&newvarname	=	3	;
else	if	5170	<=	&sic	<=	5172	then	&newvarname	=	3	;
else	if	2200	<=	&sic	<=	2269	then	&newvarname	=	4	;
else	if	2270	<=	&sic	<=	2279	then	&newvarname	=	4	;
else	if	2280	<=	&sic	<=	2284	then	&newvarname	=	4	;
else	if	2290	<=	&sic	<=	2295	then	&newvarname	=	4	;
else	if	2296	<=	&sic	<=	2296	then	&newvarname	=	4	;
else	if	2297	<=	&sic	<=	2297	then	&newvarname	=	4	;
else	if	2298	<=	&sic	<=	2298	then	&newvarname	=	4	;
else	if	2299	<=	&sic	<=	2299	then	&newvarname	=	4	;
else	if	2300	<=	&sic	<=	2390	then	&newvarname	=	4	;
else	if	2391	<=	&sic	<=	2392	then	&newvarname	=	4	;
else	if	2393	<=	&sic	<=	2395	then	&newvarname	=	4	;
else	if	2396	<=	&sic	<=	2396	then	&newvarname	=	4	;
else	if	2397	<=	&sic	<=	2399	then	&newvarname	=	4	;
else	if	3020	<=	&sic	<=	3021	then	&newvarname	=	4	;
else	if	3100	<=	&sic	<=	3111	then	&newvarname	=	4	;
else	if	3130	<=	&sic	<=	3131	then	&newvarname	=	4	;
else	if	3140	<=	&sic	<=	3149	then	&newvarname	=	4	;
else	if	3150	<=	&sic	<=	3151	then	&newvarname	=	4	;
else	if	3963	<=	&sic	<=	3965	then	&newvarname	=	4	;
else	if	5130	<=	&sic	<=	5139	then	&newvarname	=	4	;
else	if	2510	<=	&sic	<=	2519	then	&newvarname	=	5	;
else	if	2590	<=	&sic	<=	2599	then	&newvarname	=	5	;
else	if	3060	<=	&sic	<=	3069	then	&newvarname	=	5	;
else	if	3070	<=	&sic	<=	3079	then	&newvarname	=	5	;
else	if	3080	<=	&sic	<=	3089	then	&newvarname	=	5	;
else	if	3090	<=	&sic	<=	3099	then	&newvarname	=	5	;
else	if	3630	<=	&sic	<=	3639	then	&newvarname	=	5	;
else	if	3650	<=	&sic	<=	3651	then	&newvarname	=	5	;
else	if	3652	<=	&sic	<=	3652	then	&newvarname	=	5	;
else	if	3860	<=	&sic	<=	3861	then	&newvarname	=	5	;
else	if	3870	<=	&sic	<=	3873	then	&newvarname	=	5	;
else	if	3910	<=	&sic	<=	3911	then	&newvarname	=	5	;
else	if	3914	<=	&sic	<=	3914	then	&newvarname	=	5	;
else	if	3915	<=	&sic	<=	3915	then	&newvarname	=	5	;
else	if	3930	<=	&sic	<=	3931	then	&newvarname	=	5	;
else	if	3940	<=	&sic	<=	3949	then	&newvarname	=	5	;
else	if	3960	<=	&sic	<=	3962	then	&newvarname	=	5	;
else	if	5020	<=	&sic	<=	5023	then	&newvarname	=	5	;
else	if	5064	<=	&sic	<=	5064	then	&newvarname	=	5	;
else	if	5094	<=	&sic	<=	5094	then	&newvarname	=	5	;
else	if	5099	<=	&sic	<=	5099	then	&newvarname	=	5	;
else	if	2800	<=	&sic	<=	2809	then	&newvarname	=	6	;
else	if	2810	<=	&sic	<=	2819	then	&newvarname	=	6	;
else	if	2820	<=	&sic	<=	2829	then	&newvarname	=	6	;
else	if	2860	<=	&sic	<=	2869	then	&newvarname	=	6	;
else	if	2870	<=	&sic	<=	2879	then	&newvarname	=	6	;
else	if	2890	<=	&sic	<=	2899	then	&newvarname	=	6	;
else	if	5160	<=	&sic	<=	5169	then	&newvarname	=	6	;
else	if	2100	<=	&sic	<=	2199	then	&newvarname	=	7	;
else	if	2830	<=	&sic	<=	2830	then	&newvarname	=	7	;
else	if	2831	<=	&sic	<=	2831	then	&newvarname	=	7	;
else	if	2833	<=	&sic	<=	2833	then	&newvarname	=	7	;
else	if	2834	<=	&sic	<=	2834	then	&newvarname	=	7	;
else	if	2840	<=	&sic	<=	2843	then	&newvarname	=	7	;
else	if	2844	<=	&sic	<=	2844	then	&newvarname	=	7	;
else	if	5120	<=	&sic	<=	5122	then	&newvarname	=	7	;
else	if	5194	<=	&sic	<=	5194	then	&newvarname	=	7	;
else	if	800	<=	&sic	<=	899	then	&newvarname	=	8	;
else	if	1500	<=	&sic	<=	1511	then	&newvarname	=	8	;
else	if	1520	<=	&sic	<=	1529	then	&newvarname	=	8	;
else	if	1530	<=	&sic	<=	1539	then	&newvarname	=	8	;
else	if	1540	<=	&sic	<=	1549	then	&newvarname	=	8	;
else	if	1600	<=	&sic	<=	1699	then	&newvarname	=	8	;
else	if	1700	<=	&sic	<=	1799	then	&newvarname	=	8	;
else	if	2400	<=	&sic	<=	2439	then	&newvarname	=	8	;
else	if	2440	<=	&sic	<=	2449	then	&newvarname	=	8	;
else	if	2450	<=	&sic	<=	2459	then	&newvarname	=	8	;
else	if	2490	<=	&sic	<=	2499	then	&newvarname	=	8	;
else	if	2850	<=	&sic	<=	2859	then	&newvarname	=	8	;
else	if	2950	<=	&sic	<=	2952	then	&newvarname	=	8	;
else	if	3200	<=	&sic	<=	3200	then	&newvarname	=	8	;
else	if	3210	<=	&sic	<=	3211	then	&newvarname	=	8	;
else	if	3240	<=	&sic	<=	3241	then	&newvarname	=	8	;
else	if	3250	<=	&sic	<=	3259	then	&newvarname	=	8	;
else	if	3261	<=	&sic	<=	3261	then	&newvarname	=	8	;
else	if	3264	<=	&sic	<=	3264	then	&newvarname	=	8	;
else	if	3270	<=	&sic	<=	3275	then	&newvarname	=	8	;
else	if	3280	<=	&sic	<=	3281	then	&newvarname	=	8	;
else	if	3290	<=	&sic	<=	3293	then	&newvarname	=	8	;
else	if	3420	<=	&sic	<=	3429	then	&newvarname	=	8	;
else	if	3430	<=	&sic	<=	3433	then	&newvarname	=	8	;
else	if	3440	<=	&sic	<=	3441	then	&newvarname	=	8	;
else	if	3442	<=	&sic	<=	3442	then	&newvarname	=	8	;
else	if	3446	<=	&sic	<=	3446	then	&newvarname	=	8	;
else	if	3448	<=	&sic	<=	3448	then	&newvarname	=	8	;
else	if	3449	<=	&sic	<=	3449	then	&newvarname	=	8	;
else	if	3450	<=	&sic	<=	3451	then	&newvarname	=	8	;
else	if	3452	<=	&sic	<=	3452	then	&newvarname	=	8	;
else	if	5030	<=	&sic	<=	5039	then	&newvarname	=	8	;
else	if	5070	<=	&sic	<=	5078	then	&newvarname	=	8	;
else	if	5198	<=	&sic	<=	5198	then	&newvarname	=	8	;
else	if	5210	<=	&sic	<=	5211	then	&newvarname	=	8	;
else	if	5230	<=	&sic	<=	5231	then	&newvarname	=	8	;
else	if	5250	<=	&sic	<=	5251	then	&newvarname	=	8	;
else	if	3300	<=	&sic	<=	3300	then	&newvarname	=	9	;
else	if	3310	<=	&sic	<=	3317	then	&newvarname	=	9	;
else	if	3320	<=	&sic	<=	3325	then	&newvarname	=	9	;
else	if	3330	<=	&sic	<=	3339	then	&newvarname	=	9	;
else	if	3340	<=	&sic	<=	3341	then	&newvarname	=	9	;
else	if	3350	<=	&sic	<=	3357	then	&newvarname	=	9	;
else	if	3360	<=	&sic	<=	3369	then	&newvarname	=	9	;
else	if	3390	<=	&sic	<=	3399	then	&newvarname	=	9	;
else	if	3410	<=	&sic	<=	3412	then	&newvarname	=	10	;
else	if	3443	<=	&sic	<=	3443	then	&newvarname	=	10	;
else	if	3444	<=	&sic	<=	3444	then	&newvarname	=	10	;
else	if	3460	<=	&sic	<=	3469	then	&newvarname	=	10	;
else	if	3470	<=	&sic	<=	3479	then	&newvarname	=	10	;
else	if	3480	<=	&sic	<=	3489	then	&newvarname	=	10	;
else	if	3490	<=	&sic	<=	3499	then	&newvarname	=	10	;
else	if	3510	<=	&sic	<=	3519	then	&newvarname	=	11	;
else	if	3520	<=	&sic	<=	3529	then	&newvarname	=	11	;
else	if	3530	<=	&sic	<=	3530	then	&newvarname	=	11	;
else	if	3531	<=	&sic	<=	3531	then	&newvarname	=	11	;
else	if	3532	<=	&sic	<=	3532	then	&newvarname	=	11	;
else	if	3533	<=	&sic	<=	3533	then	&newvarname	=	11	;
else	if	3534	<=	&sic	<=	3534	then	&newvarname	=	11	;
else	if	3535	<=	&sic	<=	3535	then	&newvarname	=	11	;
else	if	3536	<=	&sic	<=	3536	then	&newvarname	=	11	;
else	if	3540	<=	&sic	<=	3549	then	&newvarname	=	11	;
else	if	3550	<=	&sic	<=	3559	then	&newvarname	=	11	;
else	if	3560	<=	&sic	<=	3569	then	&newvarname	=	11	;
else	if	3570	<=	&sic	<=	3579	then	&newvarname	=	11	;
else	if	3580	<=	&sic	<=	3580	then	&newvarname	=	11	;
else	if	3581	<=	&sic	<=	3581	then	&newvarname	=	11	;
else	if	3582	<=	&sic	<=	3582	then	&newvarname	=	11	;
else	if	3585	<=	&sic	<=	3585	then	&newvarname	=	11	;
else	if	3586	<=	&sic	<=	3586	then	&newvarname	=	11	;
else	if	3589	<=	&sic	<=	3589	then	&newvarname	=	11	;
else	if	3590	<=	&sic	<=	3599	then	&newvarname	=	11	;
else	if	3600	<=	&sic	<=	3600	then	&newvarname	=	11	;
else	if	3610	<=	&sic	<=	3613	then	&newvarname	=	11	;
else	if	3620	<=	&sic	<=	3621	then	&newvarname	=	11	;
else	if	3622	<=	&sic	<=	3622	then	&newvarname	=	11	;
else	if	3623	<=	&sic	<=	3629	then	&newvarname	=	11	;
else	if	3670	<=	&sic	<=	3679	then	&newvarname	=	11	;
else	if	3680	<=	&sic	<=	3680	then	&newvarname	=	11	;
else	if	3681	<=	&sic	<=	3681	then	&newvarname	=	11	;
else	if	3682	<=	&sic	<=	3682	then	&newvarname	=	11	;
else	if	3683	<=	&sic	<=	3683	then	&newvarname	=	11	;
else	if	3684	<=	&sic	<=	3684	then	&newvarname	=	11	;
else	if	3685	<=	&sic	<=	3685	then	&newvarname	=	11	;
else	if	3686	<=	&sic	<=	3686	then	&newvarname	=	11	;
else	if	3687	<=	&sic	<=	3687	then	&newvarname	=	11	;
else	if	3688	<=	&sic	<=	3688	then	&newvarname	=	11	;
else	if	3689	<=	&sic	<=	3689	then	&newvarname	=	11	;
else	if	3690	<=	&sic	<=	3690	then	&newvarname	=	11	;
else	if	3691	<=	&sic	<=	3692	then	&newvarname	=	11	;
else	if	3693	<=	&sic	<=	3693	then	&newvarname	=	11	;
else	if	3694	<=	&sic	<=	3694	then	&newvarname	=	11	;
else	if	3695	<=	&sic	<=	3695	then	&newvarname	=	11	;
else	if	3699	<=	&sic	<=	3699	then	&newvarname	=	11	;
else	if	3810	<=	&sic	<=	3810	then	&newvarname	=	11	;
else	if	3811	<=	&sic	<=	3811	then	&newvarname	=	11	;
else	if	3812	<=	&sic	<=	3812	then	&newvarname	=	11	;
else	if	3820	<=	&sic	<=	3820	then	&newvarname	=	11	;
else	if	3821	<=	&sic	<=	3821	then	&newvarname	=	11	;
else	if	3822	<=	&sic	<=	3822	then	&newvarname	=	11	;
else	if	3823	<=	&sic	<=	3823	then	&newvarname	=	11	;
else	if	3824	<=	&sic	<=	3824	then	&newvarname	=	11	;
else	if	3825	<=	&sic	<=	3825	then	&newvarname	=	11	;
else	if	3826	<=	&sic	<=	3826	then	&newvarname	=	11	;
else	if	3827	<=	&sic	<=	3827	then	&newvarname	=	11	;
else	if	3829	<=	&sic	<=	3829	then	&newvarname	=	11	;
else	if	3830	<=	&sic	<=	3839	then	&newvarname	=	11	;
else	if	3950	<=	&sic	<=	3955	then	&newvarname	=	11	;
else	if	5060	<=	&sic	<=	5060	then	&newvarname	=	11	;
else	if	5063	<=	&sic	<=	5063	then	&newvarname	=	11	;
else	if	5065	<=	&sic	<=	5065	then	&newvarname	=	11	;
else	if	5080	<=	&sic	<=	5080	then	&newvarname	=	11	;
else	if	5081	<=	&sic	<=	5081	then	&newvarname	=	11	;
else	if	3710	<=	&sic	<=	3710	then	&newvarname	=	12	;
else	if	3711	<=	&sic	<=	3711	then	&newvarname	=	12	;
else	if	3714	<=	&sic	<=	3714	then	&newvarname	=	12	;
else	if	3716	<=	&sic	<=	3716	then	&newvarname	=	12	;
else	if	3750	<=	&sic	<=	3751	then	&newvarname	=	12	;
else	if	3792	<=	&sic	<=	3792	then	&newvarname	=	12	;
else	if	5010	<=	&sic	<=	5015	then	&newvarname	=	12	;
else	if	5510	<=	&sic	<=	5521	then	&newvarname	=	12	;
else	if	5530	<=	&sic	<=	5531	then	&newvarname	=	12	;
else	if	5560	<=	&sic	<=	5561	then	&newvarname	=	12	;
else	if	5570	<=	&sic	<=	5571	then	&newvarname	=	12	;
else	if	5590	<=	&sic	<=	5599	then	&newvarname	=	12	;
else	if	3713	<=	&sic	<=	3713	then	&newvarname	=	13	;
else	if	3715	<=	&sic	<=	3715	then	&newvarname	=	13	;
else	if	3720	<=	&sic	<=	3720	then	&newvarname	=	13	;
else	if	3721	<=	&sic	<=	3721	then	&newvarname	=	13	;
else	if	3724	<=	&sic	<=	3724	then	&newvarname	=	13	;
else	if	3725	<=	&sic	<=	3725	then	&newvarname	=	13	;
else	if	3728	<=	&sic	<=	3728	then	&newvarname	=	13	;
else	if	3730	<=	&sic	<=	3731	then	&newvarname	=	13	;
else	if	3732	<=	&sic	<=	3732	then	&newvarname	=	13	;
else	if	3740	<=	&sic	<=	3743	then	&newvarname	=	13	;
else	if	3760	<=	&sic	<=	3769	then	&newvarname	=	13	;
else	if	3790	<=	&sic	<=	3790	then	&newvarname	=	13	;
else	if	3795	<=	&sic	<=	3795	then	&newvarname	=	13	;
else	if	3799	<=	&sic	<=	3799	then	&newvarname	=	13	;
else	if	4000	<=	&sic	<=	4013	then	&newvarname	=	13	;
else	if	4100	<=	&sic	<=	4100	then	&newvarname	=	13	;
else	if	4110	<=	&sic	<=	4119	then	&newvarname	=	13	;
else	if	4120	<=	&sic	<=	4121	then	&newvarname	=	13	;
else	if	4130	<=	&sic	<=	4131	then	&newvarname	=	13	;
else	if	4140	<=	&sic	<=	4142	then	&newvarname	=	13	;
else	if	4150	<=	&sic	<=	4151	then	&newvarname	=	13	;
else	if	4170	<=	&sic	<=	4173	then	&newvarname	=	13	;
else	if	4190	<=	&sic	<=	4199	then	&newvarname	=	13	;
else	if	4200	<=	&sic	<=	4200	then	&newvarname	=	13	;
else	if	4210	<=	&sic	<=	4219	then	&newvarname	=	13	;
else	if	4220	<=	&sic	<=	4229	then	&newvarname	=	13	;
else	if	4230	<=	&sic	<=	4231	then	&newvarname	=	13	;
else	if	4400	<=	&sic	<=	4499	then	&newvarname	=	13	;
else	if	4500	<=	&sic	<=	4599	then	&newvarname	=	13	;
else	if	4600	<=	&sic	<=	4699	then	&newvarname	=	13	;
else	if	4700	<=	&sic	<=	4700	then	&newvarname	=	13	;
else	if	4710	<=	&sic	<=	4712	then	&newvarname	=	13	;
else	if	4720	<=	&sic	<=	4729	then	&newvarname	=	13	;
else	if	4730	<=	&sic	<=	4739	then	&newvarname	=	13	;
else	if	4740	<=	&sic	<=	4742	then	&newvarname	=	13	;
else	if	4780	<=	&sic	<=	4780	then	&newvarname	=	13	;
else	if	4783	<=	&sic	<=	4783	then	&newvarname	=	13	;
else	if	4785	<=	&sic	<=	4785	then	&newvarname	=	13	;
else	if	4789	<=	&sic	<=	4789	then	&newvarname	=	13	;
else	if	4900	<=	&sic	<=	4900	then	&newvarname	=	14	;
else	if	4910	<=	&sic	<=	4911	then	&newvarname	=	14	;
else	if	4920	<=	&sic	<=	4922	then	&newvarname	=	14	;
else	if	4923	<=	&sic	<=	4923	then	&newvarname	=	14	;
else	if	4924	<=	&sic	<=	4925	then	&newvarname	=	14	;
else	if	4930	<=	&sic	<=	4931	then	&newvarname	=	14	;
else	if	4932	<=	&sic	<=	4932	then	&newvarname	=	14	;
else	if	4939	<=	&sic	<=	4939	then	&newvarname	=	14	;
else	if	4940	<=	&sic	<=	4942	then	&newvarname	=	14	;
else	if	5260	<=	&sic	<=	5261	then	&newvarname	=	15	;
else	if	5270	<=	&sic	<=	5271	then	&newvarname	=	15	;
else	if	5300	<=	&sic	<=	5300	then	&newvarname	=	15	;
else	if	5310	<=	&sic	<=	5311	then	&newvarname	=	15	;
else	if	5320	<=	&sic	<=	5320	then	&newvarname	=	15	;
else	if	5330	<=	&sic	<=	5331	then	&newvarname	=	15	;
else	if	5334	<=	&sic	<=	5334	then	&newvarname	=	15	;
else	if	5390	<=	&sic	<=	5399	then	&newvarname	=	15	;
else	if	5400	<=	&sic	<=	5400	then	&newvarname	=	15	;
else	if	5410	<=	&sic	<=	5411	then	&newvarname	=	15	;
else	if	5412	<=	&sic	<=	5412	then	&newvarname	=	15	;
else	if	5420	<=	&sic	<=	5421	then	&newvarname	=	15	;
else	if	5430	<=	&sic	<=	5431	then	&newvarname	=	15	;
else	if	5440	<=	&sic	<=	5441	then	&newvarname	=	15	;
else	if	5450	<=	&sic	<=	5451	then	&newvarname	=	15	;
else	if	5460	<=	&sic	<=	5461	then	&newvarname	=	15	;
else	if	5490	<=	&sic	<=	5499	then	&newvarname	=	15	;
else	if	5540	<=	&sic	<=	5541	then	&newvarname	=	15	;
else	if	5550	<=	&sic	<=	5551	then	&newvarname	=	15	;
else	if	5600	<=	&sic	<=	5699	then	&newvarname	=	15	;
else	if	5700	<=	&sic	<=	5700	then	&newvarname	=	15	;
else	if	5710	<=	&sic	<=	5719	then	&newvarname	=	15	;
else	if	5720	<=	&sic	<=	5722	then	&newvarname	=	15	;
else	if	5730	<=	&sic	<=	5733	then	&newvarname	=	15	;
else	if	5734	<=	&sic	<=	5734	then	&newvarname	=	15	;
else	if	5735	<=	&sic	<=	5735	then	&newvarname	=	15	;
else	if	5736	<=	&sic	<=	5736	then	&newvarname	=	15	;
else	if	5750	<=	&sic	<=	5750	then	&newvarname	=	15	;
else	if	5800	<=	&sic	<=	5813	then	&newvarname	=	15	;
else	if	5890	<=	&sic	<=	5890	then	&newvarname	=	15	;
else	if	5900	<=	&sic	<=	5900	then	&newvarname	=	15	;
else	if	5910	<=	&sic	<=	5912	then	&newvarname	=	15	;
else	if	5920	<=	&sic	<=	5921	then	&newvarname	=	15	;
else	if	5930	<=	&sic	<=	5932	then	&newvarname	=	15	;
else	if	5940	<=	&sic	<=	5940	then	&newvarname	=	15	;
else	if	5941	<=	&sic	<=	5941	then	&newvarname	=	15	;
else	if	5942	<=	&sic	<=	5942	then	&newvarname	=	15	;
else	if	5943	<=	&sic	<=	5943	then	&newvarname	=	15	;
else	if	5944	<=	&sic	<=	5944	then	&newvarname	=	15	;
else	if	5945	<=	&sic	<=	5945	then	&newvarname	=	15	;
else	if	5946	<=	&sic	<=	5946	then	&newvarname	=	15	;
else	if	5947	<=	&sic	<=	5947	then	&newvarname	=	15	;
else	if	5948	<=	&sic	<=	5948	then	&newvarname	=	15	;
else	if	5949	<=	&sic	<=	5949	then	&newvarname	=	15	;
else	if	5960	<=	&sic	<=	5963	then	&newvarname	=	15	;
else	if	5980	<=	&sic	<=	5989	then	&newvarname	=	15	;
else	if	5990	<=	&sic	<=	5990	then	&newvarname	=	15	;
else	if	5992	<=	&sic	<=	5992	then	&newvarname	=	15	;
else	if	5993	<=	&sic	<=	5993	then	&newvarname	=	15	;
else	if	5994	<=	&sic	<=	5994	then	&newvarname	=	15	;
else	if	5995	<=	&sic	<=	5995	then	&newvarname	=	15	;
else	if	5999	<=	&sic	<=	5999	then	&newvarname	=	15	;
else	if	6010	<=	&sic	<=	6019	then	&newvarname	=	16	;
else	if	6020	<=	&sic	<=	6020	then	&newvarname	=	16	;
else	if	6021	<=	&sic	<=	6021	then	&newvarname	=	16	;
else	if	6022	<=	&sic	<=	6022	then	&newvarname	=	16	;
else	if	6023	<=	&sic	<=	6023	then	&newvarname	=	16	;
else	if	6025	<=	&sic	<=	6025	then	&newvarname	=	16	;
else	if	6026	<=	&sic	<=	6026	then	&newvarname	=	16	;
else	if	6028	<=	&sic	<=	6029	then	&newvarname	=	16	;
else	if	6030	<=	&sic	<=	6036	then	&newvarname	=	16	;
else	if	6040	<=	&sic	<=	6049	then	&newvarname	=	16	;
else	if	6050	<=	&sic	<=	6059	then	&newvarname	=	16	;
else	if	6060	<=	&sic	<=	6062	then	&newvarname	=	16	;
else	if	6080	<=	&sic	<=	6082	then	&newvarname	=	16	;
else	if	6090	<=	&sic	<=	6099	then	&newvarname	=	16	;
else	if	6100	<=	&sic	<=	6100	then	&newvarname	=	16	;
else	if	6110	<=	&sic	<=	6111	then	&newvarname	=	16	;
else	if	6112	<=	&sic	<=	6112	then	&newvarname	=	16	;
else	if	6120	<=	&sic	<=	6129	then	&newvarname	=	16	;
else	if	6140	<=	&sic	<=	6149	then	&newvarname	=	16	;
else	if	6150	<=	&sic	<=	6159	then	&newvarname	=	16	;
else	if	6160	<=	&sic	<=	6163	then	&newvarname	=	16	;
else	if	6172	<=	&sic	<=	6172	then	&newvarname	=	16	;
else	if	6199	<=	&sic	<=	6199	then	&newvarname	=	16	;
else	if	6200	<=	&sic	<=	6299	then	&newvarname	=	16	;
else	if	6300	<=	&sic	<=	6300	then	&newvarname	=	16	;
else	if	6310	<=	&sic	<=	6312	then	&newvarname	=	16	;
else	if	6320	<=	&sic	<=	6324	then	&newvarname	=	16	;
else	if	6330	<=	&sic	<=	6331	then	&newvarname	=	16	;
else	if	6350	<=	&sic	<=	6351	then	&newvarname	=	16	;
else	if	6360	<=	&sic	<=	6361	then	&newvarname	=	16	;
else	if	6370	<=	&sic	<=	6371	then	&newvarname	=	16	;
else	if	6390	<=	&sic	<=	6399	then	&newvarname	=	16	;
else	if	6400	<=	&sic	<=	6411	then	&newvarname	=	16	;
else	if	6500	<=	&sic	<=	6500	then	&newvarname	=	16	;
else	if	6510	<=	&sic	<=	6510	then	&newvarname	=	16	;
else	if	6512	<=	&sic	<=	6512	then	&newvarname	=	16	;
else	if	6513	<=	&sic	<=	6513	then	&newvarname	=	16	;
else	if	6514	<=	&sic	<=	6514	then	&newvarname	=	16	;
else	if	6515	<=	&sic	<=	6515	then	&newvarname	=	16	;
else	if	6517	<=	&sic	<=	6519	then	&newvarname	=	16	;
else	if	6530	<=	&sic	<=	6531	then	&newvarname	=	16	;
else	if	6532	<=	&sic	<=	6532	then	&newvarname	=	16	;
else	if	6540	<=	&sic	<=	6541	then	&newvarname	=	16	;
else	if	6550	<=	&sic	<=	6553	then	&newvarname	=	16	;
else	if	6611	<=	&sic	<=	6611	then	&newvarname	=	16	;
else	if	6700	<=	&sic	<=	6700	then	&newvarname	=	16	;
else	if	6710	<=	&sic	<=	6719	then	&newvarname	=	16	;
else	if	6720	<=	&sic	<=	6722	then	&newvarname	=	16	;
else	if	6723	<=	&sic	<=	6723	then	&newvarname	=	16	;
else	if	6724	<=	&sic	<=	6724	then	&newvarname	=	16	;
else	if	6725	<=	&sic	<=	6725	then	&newvarname	=	16	;
else	if	6726	<=	&sic	<=	6726	then	&newvarname	=	16	;
else	if	6730	<=	&sic	<=	6733	then	&newvarname	=	16	;
else	if	6790	<=	&sic	<=	6790	then	&newvarname	=	16	;
else	if	6792	<=	&sic	<=	6792	then	&newvarname	=	16	;
else	if	6794	<=	&sic	<=	6794	then	&newvarname	=	16	;
else	if	6795	<=	&sic	<=	6795	then	&newvarname	=	16	;
else	if	6798	<=	&sic	<=	6798	then	&newvarname	=	16	;
else	if	6799	<=	&sic	<=	6799	then	&newvarname	=	16	;
else	if	2520	<=	&sic	<=	2549	then	&newvarname	=	17	;
else	if	2600	<=	&sic	<=	2639	then	&newvarname	=	17	;
else	if	2640	<=	&sic	<=	2659	then	&newvarname	=	17	;
else	if	2661	<=	&sic	<=	2661	then	&newvarname	=	17	;
else	if	2670	<=	&sic	<=	2699	then	&newvarname	=	17	;
else	if	2700	<=	&sic	<=	2709	then	&newvarname	=	17	;
else	if	2710	<=	&sic	<=	2719	then	&newvarname	=	17	;
else	if	2720	<=	&sic	<=	2729	then	&newvarname	=	17	;
else	if	2730	<=	&sic	<=	2739	then	&newvarname	=	17	;
else	if	2740	<=	&sic	<=	2749	then	&newvarname	=	17	;
else	if	2750	<=	&sic	<=	2759	then	&newvarname	=	17	;
else	if	2760	<=	&sic	<=	2761	then	&newvarname	=	17	;
else	if	2770	<=	&sic	<=	2771	then	&newvarname	=	17	;
else	if	2780	<=	&sic	<=	2789	then	&newvarname	=	17	;
else	if	2790	<=	&sic	<=	2799	then	&newvarname	=	17	;
else	if	2835	<=	&sic	<=	2835	then	&newvarname	=	17	;
else	if	2836	<=	&sic	<=	2836	then	&newvarname	=	17	;
else	if	2990	<=	&sic	<=	2999	then	&newvarname	=	17	;
else	if	3000	<=	&sic	<=	3000	then	&newvarname	=	17	;
else	if	3010	<=	&sic	<=	3011	then	&newvarname	=	17	;
else	if	3041	<=	&sic	<=	3041	then	&newvarname	=	17	;
else	if	3050	<=	&sic	<=	3053	then	&newvarname	=	17	;
else	if	3160	<=	&sic	<=	3161	then	&newvarname	=	17	;
else	if	3170	<=	&sic	<=	3171	then	&newvarname	=	17	;
else	if	3172	<=	&sic	<=	3172	then	&newvarname	=	17	;
else	if	3190	<=	&sic	<=	3199	then	&newvarname	=	17	;
else	if	3220	<=	&sic	<=	3221	then	&newvarname	=	17	;
else	if	3229	<=	&sic	<=	3229	then	&newvarname	=	17	;
else	if	3230	<=	&sic	<=	3231	then	&newvarname	=	17	;
else	if	3260	<=	&sic	<=	3260	then	&newvarname	=	17	;
else	if	3262	<=	&sic	<=	3263	then	&newvarname	=	17	;
else	if	3269	<=	&sic	<=	3269	then	&newvarname	=	17	;
else	if	3295	<=	&sic	<=	3299	then	&newvarname	=	17	;
else	if	3537	<=	&sic	<=	3537	then	&newvarname	=	17	;
else	if	3640	<=	&sic	<=	3644	then	&newvarname	=	17	;
else	if	3645	<=	&sic	<=	3645	then	&newvarname	=	17	;
else	if	3646	<=	&sic	<=	3646	then	&newvarname	=	17	;
else	if	3647	<=	&sic	<=	3647	then	&newvarname	=	17	;
else	if	3648	<=	&sic	<=	3649	then	&newvarname	=	17	;
else	if	3660	<=	&sic	<=	3660	then	&newvarname	=	17	;
else	if	3661	<=	&sic	<=	3661	then	&newvarname	=	17	;
else	if	3662	<=	&sic	<=	3662	then	&newvarname	=	17	;
else	if	3663	<=	&sic	<=	3663	then	&newvarname	=	17	;
else	if	3664	<=	&sic	<=	3664	then	&newvarname	=	17	;
else	if	3665	<=	&sic	<=	3665	then	&newvarname	=	17	;
else	if	3666	<=	&sic	<=	3666	then	&newvarname	=	17	;
else	if	3669	<=	&sic	<=	3669	then	&newvarname	=	17	;
else	if	3840	<=	&sic	<=	3849	then	&newvarname	=	17	;
else	if	3850	<=	&sic	<=	3851	then	&newvarname	=	17	;
else	if	3991	<=	&sic	<=	3991	then	&newvarname	=	17	;
else	if	3993	<=	&sic	<=	3993	then	&newvarname	=	17	;
else	if	3995	<=	&sic	<=	3995	then	&newvarname	=	17	;
else	if	3996	<=	&sic	<=	3996	then	&newvarname	=	17	;
else	if	4810	<=	&sic	<=	4813	then	&newvarname	=	17	;
else	if	4820	<=	&sic	<=	4822	then	&newvarname	=	17	;
else	if	4830	<=	&sic	<=	4839	then	&newvarname	=	17	;
else	if	4840	<=	&sic	<=	4841	then	&newvarname	=	17	;
else	if	4890	<=	&sic	<=	4890	then	&newvarname	=	17	;
else	if	4891	<=	&sic	<=	4891	then	&newvarname	=	17	;
else	if	4892	<=	&sic	<=	4892	then	&newvarname	=	17	;
else	if	4899	<=	&sic	<=	4899	then	&newvarname	=	17	;
else	if	4950	<=	&sic	<=	4959	then	&newvarname	=	17	;
else	if	4960	<=	&sic	<=	4961	then	&newvarname	=	17	;
else	if	4970	<=	&sic	<=	4971	then	&newvarname	=	17	;
else	if	4991	<=	&sic	<=	4991	then	&newvarname	=	17	;
else	if	5040	<=	&sic	<=	5042	then	&newvarname	=	17	;
else	if	5043	<=	&sic	<=	5043	then	&newvarname	=	17	;
else	if	5044	<=	&sic	<=	5044	then	&newvarname	=	17	;
else	if	5045	<=	&sic	<=	5045	then	&newvarname	=	17	;
else	if	5046	<=	&sic	<=	5046	then	&newvarname	=	17	;
else	if	5047	<=	&sic	<=	5047	then	&newvarname	=	17	;
else	if	5048	<=	&sic	<=	5048	then	&newvarname	=	17	;
else	if	5049	<=	&sic	<=	5049	then	&newvarname	=	17	;
else	if	5082	<=	&sic	<=	5082	then	&newvarname	=	17	;
else	if	5083	<=	&sic	<=	5083	then	&newvarname	=	17	;
else	if	5084	<=	&sic	<=	5084	then	&newvarname	=	17	;
else	if	5085	<=	&sic	<=	5085	then	&newvarname	=	17	;
else	if	5086	<=	&sic	<=	5087	then	&newvarname	=	17	;
else	if	5088	<=	&sic	<=	5088	then	&newvarname	=	17	;
else	if	5090	<=	&sic	<=	5090	then	&newvarname	=	17	;
else	if	5091	<=	&sic	<=	5092	then	&newvarname	=	17	;
else	if	5093	<=	&sic	<=	5093	then	&newvarname	=	17	;
else	if	5100	<=	&sic	<=	5100	then	&newvarname	=	17	;
else	if	5110	<=	&sic	<=	5113	then	&newvarname	=	17	;
else	if	5199	<=	&sic	<=	5199	then	&newvarname	=	17	;
else	if	7000	<=	&sic	<=	7000	then	&newvarname	=	17	;
else	if	7010	<=	&sic	<=	7011	then	&newvarname	=	17	;
else	if	7020	<=	&sic	<=	7021	then	&newvarname	=	17	;
else	if	7030	<=	&sic	<=	7033	then	&newvarname	=	17	;
else	if	7040	<=	&sic	<=	7041	then	&newvarname	=	17	;
else	if	7200	<=	&sic	<=	7200	then	&newvarname	=	17	;
else	if	7210	<=	&sic	<=	7212	then	&newvarname	=	17	;
else	if	7213	<=	&sic	<=	7213	then	&newvarname	=	17	;
else	if	7215	<=	&sic	<=	7216	then	&newvarname	=	17	;
else	if	7217	<=	&sic	<=	7217	then	&newvarname	=	17	;
else	if	7218	<=	&sic	<=	7218	then	&newvarname	=	17	;
else	if	7219	<=	&sic	<=	7219	then	&newvarname	=	17	;
else	if	7220	<=	&sic	<=	7221	then	&newvarname	=	17	;
else	if	7230	<=	&sic	<=	7231	then	&newvarname	=	17	;
else	if	7240	<=	&sic	<=	7241	then	&newvarname	=	17	;
else	if	7250	<=	&sic	<=	7251	then	&newvarname	=	17	;
else	if	7260	<=	&sic	<=	7269	then	&newvarname	=	17	;
else	if	7290	<=	&sic	<=	7290	then	&newvarname	=	17	;
else	if	7291	<=	&sic	<=	7291	then	&newvarname	=	17	;
else	if	7299	<=	&sic	<=	7299	then	&newvarname	=	17	;
else	if	7300	<=	&sic	<=	7300	then	&newvarname	=	17	;
else	if	7310	<=	&sic	<=	7319	then	&newvarname	=	17	;
else	if	7320	<=	&sic	<=	7323	then	&newvarname	=	17	;
else	if	7330	<=	&sic	<=	7338	then	&newvarname	=	17	;
else	if	7340	<=	&sic	<=	7342	then	&newvarname	=	17	;
else	if	7349	<=	&sic	<=	7349	then	&newvarname	=	17	;
else	if	7350	<=	&sic	<=	7351	then	&newvarname	=	17	;
else	if	7352	<=	&sic	<=	7352	then	&newvarname	=	17	;
else	if	7353	<=	&sic	<=	7353	then	&newvarname	=	17	;
else	if	7359	<=	&sic	<=	7359	then	&newvarname	=	17	;
else	if	7360	<=	&sic	<=	7369	then	&newvarname	=	17	;
else	if	7370	<=	&sic	<=	7372	then	&newvarname	=	17	;
else	if	7373	<=	&sic	<=	7373	then	&newvarname	=	17	;
else	if	7374	<=	&sic	<=	7374	then	&newvarname	=	17	;
else	if	7375	<=	&sic	<=	7375	then	&newvarname	=	17	;
else	if	7376	<=	&sic	<=	7376	then	&newvarname	=	17	;
else	if	7377	<=	&sic	<=	7377	then	&newvarname	=	17	;
else	if	7378	<=	&sic	<=	7378	then	&newvarname	=	17	;
else	if	7379	<=	&sic	<=	7379	then	&newvarname	=	17	;
else	if	7380	<=	&sic	<=	7380	then	&newvarname	=	17	;
else	if	7381	<=	&sic	<=	7382	then	&newvarname	=	17	;
else	if	7383	<=	&sic	<=	7383	then	&newvarname	=	17	;
else	if	7384	<=	&sic	<=	7384	then	&newvarname	=	17	;
else	if	7385	<=	&sic	<=	7385	then	&newvarname	=	17	;
else	if	7389	<=	&sic	<=	7390	then	&newvarname	=	17	;
else	if	7391	<=	&sic	<=	7391	then	&newvarname	=	17	;
else	if	7392	<=	&sic	<=	7392	then	&newvarname	=	17	;
else	if	7393	<=	&sic	<=	7393	then	&newvarname	=	17	;
else	if	7394	<=	&sic	<=	7394	then	&newvarname	=	17	;
else	if	7395	<=	&sic	<=	7395	then	&newvarname	=	17	;
else	if	7397	<=	&sic	<=	7397	then	&newvarname	=	17	;
else	if	7399	<=	&sic	<=	7399	then	&newvarname	=	17	;
else	if	7500	<=	&sic	<=	7500	then	&newvarname	=	17	;
else	if	7510	<=	&sic	<=	7519	then	&newvarname	=	17	;
else	if	7520	<=	&sic	<=	7523	then	&newvarname	=	17	;
else	if	7530	<=	&sic	<=	7539	then	&newvarname	=	17	;
else	if	7540	<=	&sic	<=	7549	then	&newvarname	=	17	;
else	if	7600	<=	&sic	<=	7600	then	&newvarname	=	17	;
else	if	7620	<=	&sic	<=	7620	then	&newvarname	=	17	;
else	if	7622	<=	&sic	<=	7622	then	&newvarname	=	17	;
else	if	7623	<=	&sic	<=	7623	then	&newvarname	=	17	;
else	if	7629	<=	&sic	<=	7629	then	&newvarname	=	17	;
else	if	7630	<=	&sic	<=	7631	then	&newvarname	=	17	;
else	if	7640	<=	&sic	<=	7641	then	&newvarname	=	17	;
else	if	7690	<=	&sic	<=	7699	then	&newvarname	=	17	;
else	if	7800	<=	&sic	<=	7829	then	&newvarname	=	17	;
else	if	7830	<=	&sic	<=	7833	then	&newvarname	=	17	;
else	if	7840	<=	&sic	<=	7841	then	&newvarname	=	17	;
else	if	7900	<=	&sic	<=	7900	then	&newvarname	=	17	;
else	if	7910	<=	&sic	<=	7911	then	&newvarname	=	17	;
else	if	7920	<=	&sic	<=	7929	then	&newvarname	=	17	;
else	if	7930	<=	&sic	<=	7933	then	&newvarname	=	17	;
else	if	7940	<=	&sic	<=	7949	then	&newvarname	=	17	;
else	if	7980	<=	&sic	<=	7980	then	&newvarname	=	17	;
else	if	7990	<=	&sic	<=	7999	then	&newvarname	=	17	;
else	if	8000	<=	&sic	<=	8099	then	&newvarname	=	17	;
else	if	8100	<=	&sic	<=	8199	then	&newvarname	=	17	;
else	if	8200	<=	&sic	<=	8299	then	&newvarname	=	17	;
else	if	8300	<=	&sic	<=	8399	then	&newvarname	=	17	;
else	if	8400	<=	&sic	<=	8499	then	&newvarname	=	17	;
else	if	8600	<=	&sic	<=	8699	then	&newvarname	=	17	;
else	if	8700	<=	&sic	<=	8700	then	&newvarname	=	17	;
else	if	8710	<=	&sic	<=	8713	then	&newvarname	=	17	;
else	if	8720	<=	&sic	<=	8721	then	&newvarname	=	17	;
else	if	8730	<=	&sic	<=	8734	then	&newvarname	=	17	;
else	if	8740	<=	&sic	<=	8748	then	&newvarname	=	17	;
else	if	8800	<=	&sic	<=	8899	then	&newvarname	=	17	;
else	if	8900	<=	&sic	<=	8910	then	&newvarname	=	17	;
else	if	8911	<=	&sic	<=	8911	then	&newvarname	=	17	;
else	if	8920	<=	&sic	<=	8999	then	&newvarname	=	17	;
else &newvarname = 17;
run;

proc format;
   value ff
	1	="Food"
 2	="Mining and Minerals"
 3	="Oil and Petro Products"
 4	="Textiles, Apparel & Footware"
 5	="Consumer Durables"
 6	="Chemicals"
 7	="Drugs, Soap, Prfums, Tobacco"
 8	="Construction"
 9	="Steel"
10	="Fabricated Products"
11	="Machinery and Business Equipment"
12	="Automobiles"
13	="Transporation"
14	="Utilities"
15	="Retail Stores"
16	="Financial Institutions"
17	="Other";
run;

%mend;


*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
*CREATES FAMA-FRENCH 30 INDUSTRY CLASSIFICATIONS
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro ff30(data=,newvarname=industry,sic=sic,out=&data);

data &out;
    set &data;
    &newvarname = 30;
if	100	<= &sic <=	199	then &newvarname = 	1	;
else if	200	<= &sic <=	299	then &newvarname = 	1	;
else if	700	<= &sic <=	799	then &newvarname = 	1	;
else if	910	<= &sic <=	919	then &newvarname = 	1	;
else if	2000	<= &sic <=	2009	then &newvarname = 	1	;
else if	2010	<= &sic <=	2019	then &newvarname = 	1	;
else if	2020	<= &sic <=	2029	then &newvarname = 	1	;
else if	2030	<= &sic <=	2039	then &newvarname = 	1	;
else if	2040	<= &sic <=	2046	then &newvarname = 	1	;
else if	2048	<= &sic <=	2048	then &newvarname = 	1	;
else if	2050	<= &sic <=	2059	then &newvarname = 	1	;
else if	2060	<= &sic <=	2063	then &newvarname = 	1	;
else if	2064	<= &sic <=	2068	then &newvarname = 	1	;
else if	2070	<= &sic <=	2079	then &newvarname = 	1	;
else if	2086	<= &sic <=	2086	then &newvarname = 	1	;
else if	2087	<= &sic <=	2087	then &newvarname = 	1	;
else if	2090	<= &sic <=	2092	then &newvarname = 	1	;
else if	2095	<= &sic <=	2095	then &newvarname = 	1	;
else if	2096	<= &sic <=	2096	then &newvarname = 	1	;
else if	2097	<= &sic <=	2097	then &newvarname = 	1	;
else if	2098	<= &sic <=	2099	then &newvarname = 	1	;
else if	2080	<= &sic <=	2080	then &newvarname = 	2	;
else if	2082	<= &sic <=	2082	then &newvarname = 	2	;
else if	2083	<= &sic <=	2083	then &newvarname = 	2	;
else if	2084	<= &sic <=	2084	then &newvarname = 	2	;
else if	2085	<= &sic <=	2085	then &newvarname = 	2	;
else if	2100	<= &sic <=	2199	then &newvarname = 	3	;
else if	920	<= &sic <=	999	then &newvarname = 	4	;
else if	3650	<= &sic <=	3651	then &newvarname = 	4	;
else if	3652	<= &sic <=	3652	then &newvarname = 	4	;
else if	3732	<= &sic <=	3732	then &newvarname = 	4	;
else if	3930	<= &sic <=	3931	then &newvarname = 	4	;
else if	3940	<= &sic <=	3949	then &newvarname = 	4	;
else if	7800	<= &sic <=	7829	then &newvarname = 	4	;
else if	7830	<= &sic <=	7833	then &newvarname = 	4	;
else if	7840	<= &sic <=	7841	then &newvarname = 	4	;
else if	7900	<= &sic <=	7900	then &newvarname = 	4	;
else if	7910	<= &sic <=	7911	then &newvarname = 	4	;
else if	7920	<= &sic <=	7929	then &newvarname = 	4	;
else if	7930	<= &sic <=	7933	then &newvarname = 	4	;
else if	7940	<= &sic <=	7949	then &newvarname = 	4	;
else if	7980	<= &sic <=	7980	then &newvarname = 	4	;
else if	7990	<= &sic <=	7999	then &newvarname = 	4	;
else if	2700	<= &sic <=	2709	then &newvarname = 	5	;
else if	2710	<= &sic <=	2719	then &newvarname = 	5	;
else if	2720	<= &sic <=	2729	then &newvarname = 	5	;
else if	2730	<= &sic <=	2739	then &newvarname = 	5	;
else if	2740	<= &sic <=	2749	then &newvarname = 	5	;
else if	2750	<= &sic <=	2759	then &newvarname = 	5	;
else if	2770	<= &sic <=	2771	then &newvarname = 	5	;
else if	2780	<= &sic <=	2789	then &newvarname = 	5	;
else if	2790	<= &sic <=	2799	then &newvarname = 	5	;
else if	3993	<= &sic <=	3993	then &newvarname = 	5	;
else if	2047	<= &sic <=	2047	then &newvarname = 	6	;
else if	2391	<= &sic <=	2392	then &newvarname = 	6	;
else if	2510	<= &sic <=	2519	then &newvarname = 	6	;
else if	2590	<= &sic <=	2599	then &newvarname = 	6	;
else if	2840	<= &sic <=	2843	then &newvarname = 	6	;
else if	2844	<= &sic <=	2844	then &newvarname = 	6	;
else if	3160	<= &sic <=	3161	then &newvarname = 	6	;
else if	3170	<= &sic <=	3171	then &newvarname = 	6	;
else if	3172	<= &sic <=	3172	then &newvarname = 	6	;
else if	3190	<= &sic <=	3199	then &newvarname = 	6	;
else if	3229	<= &sic <=	3229	then &newvarname = 	6	;
else if	3260	<= &sic <=	3260	then &newvarname = 	6	;
else if	3262	<= &sic <=	3263	then &newvarname = 	6	;
else if	3269	<= &sic <=	3269	then &newvarname = 	6	;
else if	3230	<= &sic <=	3231	then &newvarname = 	6	;
else if	3630	<= &sic <=	3639	then &newvarname = 	6	;
else if	3750	<= &sic <=	3751	then &newvarname = 	6	;
else if	3800	<= &sic <=	3800	then &newvarname = 	6	;
else if	3860	<= &sic <=	3861	then &newvarname = 	6	;
else if	3870	<= &sic <=	3873	then &newvarname = 	6	;
else if	3910	<= &sic <=	3911	then &newvarname = 	6	;
else if	3914	<= &sic <=	3914	then &newvarname = 	6	;
else if	3915	<= &sic <=	3915	then &newvarname = 	6	;
else if	3960	<= &sic <=	3962	then &newvarname = 	6	;
else if	3991	<= &sic <=	3991	then &newvarname = 	6	;
else if	3995	<= &sic <=	3995	then &newvarname = 	6	;
else if	2300	<= &sic <=	2390	then &newvarname = 	7	;
else if	3020	<= &sic <=	3021	then &newvarname = 	7	;
else if	3100	<= &sic <=	3111	then &newvarname = 	7	;
else if	3130	<= &sic <=	3131	then &newvarname = 	7	;
else if	3140	<= &sic <=	3149	then &newvarname = 	7	;
else if	3150	<= &sic <=	3151	then &newvarname = 	7	;
else if	3963	<= &sic <=	3965	then &newvarname = 	7	;
else if	2830	<= &sic <=	2830	then &newvarname = 	8	;
else if	2831	<= &sic <=	2831	then &newvarname = 	8	;
else if	2833	<= &sic <=	2833	then &newvarname = 	8	;
else if	2834	<= &sic <=	2834	then &newvarname = 	8	;
else if	2835	<= &sic <=	2835	then &newvarname = 	8	;
else if	2836	<= &sic <=	2836	then &newvarname = 	8	;
else if	3693	<= &sic <=	3693	then &newvarname = 	8	;
else if	3840	<= &sic <=	3849	then &newvarname = 	8	;
else if	3850	<= &sic <=	3851	then &newvarname = 	8	;
else if	8000	<= &sic <=	8099	then &newvarname = 	8	;
else if	2800	<= &sic <=	2809	then &newvarname = 	9	;
else if	2810	<= &sic <=	2819	then &newvarname = 	9	;
else if	2820	<= &sic <=	2829	then &newvarname = 	9	;
else if	2850	<= &sic <=	2859	then &newvarname = 	9	;
else if	2860	<= &sic <=	2869	then &newvarname = 	9	;
else if	2870	<= &sic <=	2879	then &newvarname = 	9	;
else if	2890	<= &sic <=	2899	then &newvarname = 	9	;
else if	2200	<= &sic <=	2269	then &newvarname = 	10	;
else if	2270	<= &sic <=	2279	then &newvarname = 	10	;
else if	2280	<= &sic <=	2284	then &newvarname = 	10	;
else if	2290	<= &sic <=	2295	then &newvarname = 	10	;
else if	2297	<= &sic <=	2297	then &newvarname = 	10	;
else if	2298	<= &sic <=	2298	then &newvarname = 	10	;
else if	2299	<= &sic <=	2299	then &newvarname = 	10	;
else if	2393	<= &sic <=	2395	then &newvarname = 	10	;
else if	2397	<= &sic <=	2399	then &newvarname = 	10	;
else if	800	<= &sic <=	899	then &newvarname = 	11	;
else if	1500	<= &sic <=	1511	then &newvarname = 	11	;
else if	1520	<= &sic <=	1529	then &newvarname = 	11	;
else if	1530	<= &sic <=	1539	then &newvarname = 	11	;
else if	1540	<= &sic <=	1549	then &newvarname = 	11	;
else if	1600	<= &sic <=	1699	then &newvarname = 	11	;
else if	1700	<= &sic <=	1799	then &newvarname = 	11	;
else if	2400	<= &sic <=	2439	then &newvarname = 	11	;
else if	2450	<= &sic <=	2459	then &newvarname = 	11	;
else if	2490	<= &sic <=	2499	then &newvarname = 	11	;
else if	2660	<= &sic <=	2661	then &newvarname = 	11	;
else if	2950	<= &sic <=	2952	then &newvarname = 	11	;
else if	3200	<= &sic <=	3200	then &newvarname = 	11	;
else if	3210	<= &sic <=	3211	then &newvarname = 	11	;
else if	3240	<= &sic <=	3241	then &newvarname = 	11	;
else if	3250	<= &sic <=	3259	then &newvarname = 	11	;
else if	3261	<= &sic <=	3261	then &newvarname = 	11	;
else if	3264	<= &sic <=	3264	then &newvarname = 	11	;
else if	3270	<= &sic <=	3275	then &newvarname = 	11	;
else if	3280	<= &sic <=	3281	then &newvarname = 	11	;
else if	3290	<= &sic <=	3293	then &newvarname = 	11	;
else if	3295	<= &sic <=	3299	then &newvarname = 	11	;
else if	3420	<= &sic <=	3429	then &newvarname = 	11	;
else if	3430	<= &sic <=	3433	then &newvarname = 	11	;
else if	3440	<= &sic <=	3441	then &newvarname = 	11	;
else if	3442	<= &sic <=	3442	then &newvarname = 	11	;
else if	3446	<= &sic <=	3446	then &newvarname = 	11	;
else if	3448	<= &sic <=	3448	then &newvarname = 	11	;
else if	3449	<= &sic <=	3449	then &newvarname = 	11	;
else if	3450	<= &sic <=	3451	then &newvarname = 	11	;
else if	3452	<= &sic <=	3452	then &newvarname = 	11	;
else if	3490	<= &sic <=	3499	then &newvarname = 	11	;
else if	3996	<= &sic <=	3996	then &newvarname = 	11	;
else if	3300	<= &sic <=	3300	then &newvarname = 	12	;
else if	3310	<= &sic <=	3317	then &newvarname = 	12	;
else if	3320	<= &sic <=	3325	then &newvarname = 	12	;
else if	3330	<= &sic <=	3339	then &newvarname = 	12	;
else if	3340	<= &sic <=	3341	then &newvarname = 	12	;
else if	3350	<= &sic <=	3357	then &newvarname = 	12	;
else if	3360	<= &sic <=	3369	then &newvarname = 	12	;
else if	3370	<= &sic <=	3379	then &newvarname = 	12	;
else if	3390	<= &sic <=	3399	then &newvarname = 	12	;
else if	3400	<= &sic <=	3400	then &newvarname = 	13	;
else if	3443	<= &sic <=	3443	then &newvarname = 	13	;
else if	3444	<= &sic <=	3444	then &newvarname = 	13	;
else if	3460	<= &sic <=	3469	then &newvarname = 	13	;
else if	3470	<= &sic <=	3479	then &newvarname = 	13	;
else if	3510	<= &sic <=	3519	then &newvarname = 	13	;
else if	3520	<= &sic <=	3529	then &newvarname = 	13	;
else if	3530	<= &sic <=	3530	then &newvarname = 	13	;
else if	3531	<= &sic <=	3531	then &newvarname = 	13	;
else if	3532	<= &sic <=	3532	then &newvarname = 	13	;
else if	3533	<= &sic <=	3533	then &newvarname = 	13	;
else if	3534	<= &sic <=	3534	then &newvarname = 	13	;
else if	3535	<= &sic <=	3535	then &newvarname = 	13	;
else if	3536	<= &sic <=	3536	then &newvarname = 	13	;
else if	3538	<= &sic <=	3538	then &newvarname = 	13	;
else if	3540	<= &sic <=	3549	then &newvarname = 	13	;
else if	3550	<= &sic <=	3559	then &newvarname = 	13	;
else if	3560	<= &sic <=	3569	then &newvarname = 	13	;
else if	3580	<= &sic <=	3580	then &newvarname = 	13	;
else if	3581	<= &sic <=	3581	then &newvarname = 	13	;
else if	3582	<= &sic <=	3582	then &newvarname = 	13	;
else if	3585	<= &sic <=	3585	then &newvarname = 	13	;
else if	3586	<= &sic <=	3586	then &newvarname = 	13	;
else if	3589	<= &sic <=	3589	then &newvarname = 	13	;
else if	3590	<= &sic <=	3599	then &newvarname = 	13	;
else if	3600	<= &sic <=	3600	then &newvarname = 	14	;
else if	3610	<= &sic <=	3613	then &newvarname = 	14	;
else if	3620	<= &sic <=	3621	then &newvarname = 	14	;
else if	3623	<= &sic <=	3629	then &newvarname = 	14	;
else if	3640	<= &sic <=	3644	then &newvarname = 	14	;
else if	3645	<= &sic <=	3645	then &newvarname = 	14	;
else if	3646	<= &sic <=	3646	then &newvarname = 	14	;
else if	3648	<= &sic <=	3649	then &newvarname = 	14	;
else if	3660	<= &sic <=	3660	then &newvarname = 	14	;
else if	3690	<= &sic <=	3690	then &newvarname = 	14	;
else if	3691	<= &sic <=	3692	then &newvarname = 	14	;
else if	3699	<= &sic <=	3699	then &newvarname = 	14	;
else if	2296	<= &sic <=	2296	then &newvarname = 	15	;
else if	2396	<= &sic <=	2396	then &newvarname = 	15	;
else if	3010	<= &sic <=	3011	then &newvarname = 	15	;
else if	3537	<= &sic <=	3537	then &newvarname = 	15	;
else if	3647	<= &sic <=	3647	then &newvarname = 	15	;
else if	3694	<= &sic <=	3694	then &newvarname = 	15	;
else if	3700	<= &sic <=	3700	then &newvarname = 	15	;
else if	3710	<= &sic <=	3710	then &newvarname = 	15	;
else if	3711	<= &sic <=	3711	then &newvarname = 	15	;
else if	3713	<= &sic <=	3713	then &newvarname = 	15	;
else if	3714	<= &sic <=	3714	then &newvarname = 	15	;
else if	3715	<= &sic <=	3715	then &newvarname = 	15	;
else if	3716	<= &sic <=	3716	then &newvarname = 	15	;
else if	3792	<= &sic <=	3792	then &newvarname = 	15	;
else if	3790	<= &sic <=	3791	then &newvarname = 	15	;
else if	3799	<= &sic <=	3799	then &newvarname = 	15	;
else if	3720	<= &sic <=	3720	then &newvarname = 	16	;
else if	3721	<= &sic <=	3721	then &newvarname = 	16	;
else if	3723	<= &sic <=	3724	then &newvarname = 	16	;
else if	3725	<= &sic <=	3725	then &newvarname = 	16	;
else if	3728	<= &sic <=	3729	then &newvarname = 	16	;
else if	3730	<= &sic <=	3731	then &newvarname = 	16	;
else if	3740	<= &sic <=	3743	then &newvarname = 	16	;
else if	1000	<= &sic <=	1009	then &newvarname = 	17	;
else if	1010	<= &sic <=	1019	then &newvarname = 	17	;
else if	1020	<= &sic <=	1029	then &newvarname = 	17	;
else if	1030	<= &sic <=	1039	then &newvarname = 	17	;
else if	1040	<= &sic <=	1049	then &newvarname = 	17	;
else if	1050	<= &sic <=	1059	then &newvarname = 	17	;
else if	1060	<= &sic <=	1069	then &newvarname = 	17	;
else if	1070	<= &sic <=	1079	then &newvarname = 	17	;
else if	1080	<= &sic <=	1089	then &newvarname = 	17	;
else if	1090	<= &sic <=	1099	then &newvarname = 	17	;
else if	1100	<= &sic <=	1119	then &newvarname = 	17	;
else if	1400	<= &sic <=	1499	then &newvarname = 	17	;
else if	1200	<= &sic <=	1299	then &newvarname = 	18	;
else if	1300	<= &sic <=	1300	then &newvarname = 	19	;
else if	1310	<= &sic <=	1319	then &newvarname = 	19	;
else if	1320	<= &sic <=	1329	then &newvarname = 	19	;
else if	1330	<= &sic <=	1339	then &newvarname = 	19	;
else if	1370	<= &sic <=	1379	then &newvarname = 	19	;
else if	1380	<= &sic <=	1380	then &newvarname = 	19	;
else if	1381	<= &sic <=	1381	then &newvarname = 	19	;
else if	1382	<= &sic <=	1382	then &newvarname = 	19	;
else if	1389	<= &sic <=	1389	then &newvarname = 	19	;
else if	2900	<= &sic <=	2912	then &newvarname = 	19	;
else if	2990	<= &sic <=	2999	then &newvarname = 	19	;
else if	4900	<= &sic <=	4900	then &newvarname = 	20	;
else if	4910	<= &sic <=	4911	then &newvarname = 	20	;
else if	4920	<= &sic <=	4922	then &newvarname = 	20	;
else if	4923	<= &sic <=	4923	then &newvarname = 	20	;
else if	4924	<= &sic <=	4925	then &newvarname = 	20	;
else if	4930	<= &sic <=	4931	then &newvarname = 	20	;
else if	4932	<= &sic <=	4932	then &newvarname = 	20	;
else if	4939	<= &sic <=	4939	then &newvarname = 	20	;
else if	4940	<= &sic <=	4942	then &newvarname = 	20	;
else if	4800	<= &sic <=	4800	then &newvarname = 	21	;
else if	4810	<= &sic <=	4813	then &newvarname = 	21	;
else if	4820	<= &sic <=	4822	then &newvarname = 	21	;
else if	4830	<= &sic <=	4839	then &newvarname = 	21	;
else if	4840	<= &sic <=	4841	then &newvarname = 	21	;
else if	4880	<= &sic <=	4889	then &newvarname = 	21	;
else if	4890	<= &sic <=	4890	then &newvarname = 	21	;
else if	4891	<= &sic <=	4891	then &newvarname = 	21	;
else if	4892	<= &sic <=	4892	then &newvarname = 	21	;
else if	4899	<= &sic <=	4899	then &newvarname = 	21	;
else if	7020	<= &sic <=	7021	then &newvarname = 	22	;
else if	7030	<= &sic <=	7033	then &newvarname = 	22	;
else if	7200	<= &sic <=	7200	then &newvarname = 	22	;
else if	7210	<= &sic <=	7212	then &newvarname = 	22	;
else if	7214	<= &sic <=	7214	then &newvarname = 	22	;
else if	7215	<= &sic <=	7216	then &newvarname = 	22	;
else if	7217	<= &sic <=	7217	then &newvarname = 	22	;
else if	7218	<= &sic <=	7218	then &newvarname = 	22	;
else if	7219	<= &sic <=	7219	then &newvarname = 	22	;
else if	7220	<= &sic <=	7221	then &newvarname = 	22	;
else if	7230	<= &sic <=	7231	then &newvarname = 	22	;
else if	7240	<= &sic <=	7241	then &newvarname = 	22	;
else if	7250	<= &sic <=	7251	then &newvarname = 	22	;
else if	7260	<= &sic <=	7269	then &newvarname = 	22	;
else if	7270	<= &sic <=	7290	then &newvarname = 	22	;
else if	7291	<= &sic <=	7291	then &newvarname = 	22	;
else if	7292	<= &sic <=	7299	then &newvarname = 	22	;
else if	7300	<= &sic <=	7300	then &newvarname = 	22	;
else if	7310	<= &sic <=	7319	then &newvarname = 	22	;
else if	7320	<= &sic <=	7329	then &newvarname = 	22	;
else if	7330	<= &sic <=	7339	then &newvarname = 	22	;
else if	7340	<= &sic <=	7342	then &newvarname = 	22	;
else if	7349	<= &sic <=	7349	then &newvarname = 	22	;
else if	7350	<= &sic <=	7351	then &newvarname = 	22	;
else if	7352	<= &sic <=	7352	then &newvarname = 	22	;
else if	7353	<= &sic <=	7353	then &newvarname = 	22	;
else if	7359	<= &sic <=	7359	then &newvarname = 	22	;
else if	7360	<= &sic <=	7369	then &newvarname = 	22	;
else if	7370	<= &sic <=	7372	then &newvarname = 	22	;
else if	7374	<= &sic <=	7374	then &newvarname = 	22	;
else if	7375	<= &sic <=	7375	then &newvarname = 	22	;
else if	7376	<= &sic <=	7376	then &newvarname = 	22	;
else if	7377	<= &sic <=	7377	then &newvarname = 	22	;
else if	7378	<= &sic <=	7378	then &newvarname = 	22	;
else if	7379	<= &sic <=	7379	then &newvarname = 	22	;
else if	7380	<= &sic <=	7380	then &newvarname = 	22	;
else if	7381	<= &sic <=	7382	then &newvarname = 	22	;
else if	7383	<= &sic <=	7383	then &newvarname = 	22	;
else if	7384	<= &sic <=	7384	then &newvarname = 	22	;
else if	7385	<= &sic <=	7385	then &newvarname = 	22	;
else if	7389	<= &sic <=	7390	then &newvarname = 	22	;
else if	7391	<= &sic <=	7391	then &newvarname = 	22	;
else if	7392	<= &sic <=	7392	then &newvarname = 	22	;
else if	7393	<= &sic <=	7393	then &newvarname = 	22	;
else if	7394	<= &sic <=	7394	then &newvarname = 	22	;
else if	7395	<= &sic <=	7395	then &newvarname = 	22	;
else if	7396	<= &sic <=	7396	then &newvarname = 	22	;
else if	7397	<= &sic <=	7397	then &newvarname = 	22	;
else if	7399	<= &sic <=	7399	then &newvarname = 	22	;
else if	7500	<= &sic <=	7500	then &newvarname = 	22	;
else if	7510	<= &sic <=	7519	then &newvarname = 	22	;
else if	7520	<= &sic <=	7529	then &newvarname = 	22	;
else if	7530	<= &sic <=	7539	then &newvarname = 	22	;
else if	7540	<= &sic <=	7549	then &newvarname = 	22	;
else if	7600	<= &sic <=	7600	then &newvarname = 	22	;
else if	7620	<= &sic <=	7620	then &newvarname = 	22	;
else if	7622	<= &sic <=	7622	then &newvarname = 	22	;
else if	7623	<= &sic <=	7623	then &newvarname = 	22	;
else if	7629	<= &sic <=	7629	then &newvarname = 	22	;
else if	7630	<= &sic <=	7631	then &newvarname = 	22	;
else if	7640	<= &sic <=	7641	then &newvarname = 	22	;
else if	7690	<= &sic <=	7699	then &newvarname = 	22	;
else if	8100	<= &sic <=	8199	then &newvarname = 	22	;
else if	8200	<= &sic <=	8299	then &newvarname = 	22	;
else if	8300	<= &sic <=	8399	then &newvarname = 	22	;
else if	8400	<= &sic <=	8499	then &newvarname = 	22	;
else if	8600	<= &sic <=	8699	then &newvarname = 	22	;
else if	8700	<= &sic <=	8700	then &newvarname = 	22	;
else if	8710	<= &sic <=	8713	then &newvarname = 	22	;
else if	8720	<= &sic <=	8721	then &newvarname = 	22	;
else if	8730	<= &sic <=	8734	then &newvarname = 	22	;
else if	8740	<= &sic <=	8748	then &newvarname = 	22	;
else if	8800	<= &sic <=	8899	then &newvarname = 	22	;
else if	8900	<= &sic <=	8910	then &newvarname = 	22	;
else if	8911	<= &sic <=	8911	then &newvarname = 	22	;
else if	8920	<= &sic <=	8999	then &newvarname = 	22	;
else if	3570	<= &sic <=	3579	then &newvarname = 	23	;
else if	3622	<= &sic <=	3622	then &newvarname = 	23	;
else if	3661	<= &sic <=	3661	then &newvarname = 	23	;
else if	3662	<= &sic <=	3662	then &newvarname = 	23	;
else if	3663	<= &sic <=	3663	then &newvarname = 	23	;
else if	3664	<= &sic <=	3664	then &newvarname = 	23	;
else if	3665	<= &sic <=	3665	then &newvarname = 	23	;
else if	3666	<= &sic <=	3666	then &newvarname = 	23	;
else if	3669	<= &sic <=	3669	then &newvarname = 	23	;
else if	3670	<= &sic <=	3679	then &newvarname = 	23	;
else if	3680	<= &sic <=	3680	then &newvarname = 	23	;
else if	3681	<= &sic <=	3681	then &newvarname = 	23	;
else if	3682	<= &sic <=	3682	then &newvarname = 	23	;
else if	3683	<= &sic <=	3683	then &newvarname = 	23	;
else if	3684	<= &sic <=	3684	then &newvarname = 	23	;
else if	3685	<= &sic <=	3685	then &newvarname = 	23	;
else if	3686	<= &sic <=	3686	then &newvarname = 	23	;
else if	3687	<= &sic <=	3687	then &newvarname = 	23	;
else if	3688	<= &sic <=	3688	then &newvarname = 	23	;
else if	3689	<= &sic <=	3689	then &newvarname = 	23	;
else if	3695	<= &sic <=	3695	then &newvarname = 	23	;
else if	3810	<= &sic <=	3810	then &newvarname = 	23	;
else if	3811	<= &sic <=	3811	then &newvarname = 	23	;
else if	3812	<= &sic <=	3812	then &newvarname = 	23	;
else if	3820	<= &sic <=	3820	then &newvarname = 	23	;
else if	3821	<= &sic <=	3821	then &newvarname = 	23	;
else if	3822	<= &sic <=	3822	then &newvarname = 	23	;
else if	3823	<= &sic <=	3823	then &newvarname = 	23	;
else if	3824	<= &sic <=	3824	then &newvarname = 	23	;
else if	3825	<= &sic <=	3825	then &newvarname = 	23	;
else if	3826	<= &sic <=	3826	then &newvarname = 	23	;
else if	3827	<= &sic <=	3827	then &newvarname = 	23	;
else if	3829	<= &sic <=	3829	then &newvarname = 	23	;
else if	3830	<= &sic <=	3839	then &newvarname = 	23	;
else if	7373	<= &sic <=	7373	then &newvarname = 	23	;
else if	2440	<= &sic <=	2449	then &newvarname = 	24	;
else if	2520	<= &sic <=	2549	then &newvarname = 	24	;
else if	2600	<= &sic <=	2639	then &newvarname = 	24	;
else if	2640	<= &sic <=	2659	then &newvarname = 	24	;
else if	2670	<= &sic <=	2699	then &newvarname = 	24	;
else if	2760	<= &sic <=	2761	then &newvarname = 	24	;
else if	3220	<= &sic <=	3221	then &newvarname = 	24	;
else if	3410	<= &sic <=	3412	then &newvarname = 	24	;
else if	3950	<= &sic <=	3955	then &newvarname = 	24	;
else if	4000	<= &sic <=	4013	then &newvarname = 	25	;
else if	4040	<= &sic <=	4049	then &newvarname = 	25	;
else if	4100	<= &sic <=	4100	then &newvarname = 	25	;
else if	4110	<= &sic <=	4119	then &newvarname = 	25	;
else if	4120	<= &sic <=	4121	then &newvarname = 	25	;
else if	4130	<= &sic <=	4131	then &newvarname = 	25	;
else if	4140	<= &sic <=	4142	then &newvarname = 	25	;
else if	4150	<= &sic <=	4151	then &newvarname = 	25	;
else if	4170	<= &sic <=	4173	then &newvarname = 	25	;
else if	4190	<= &sic <=	4199	then &newvarname = 	25	;
else if	4200	<= &sic <=	4200	then &newvarname = 	25	;
else if	4210	<= &sic <=	4219	then &newvarname = 	25	;
else if	4220	<= &sic <=	4229	then &newvarname = 	25	;
else if	4230	<= &sic <=	4231	then &newvarname = 	25	;
else if	4240	<= &sic <=	4249	then &newvarname = 	25	;
else if	4400	<= &sic <=	4499	then &newvarname = 	25	;
else if	4500	<= &sic <=	4599	then &newvarname = 	25	;
else if	4600	<= &sic <=	4699	then &newvarname = 	25	;
else if	4700	<= &sic <=	4700	then &newvarname = 	25	;
else if	4710	<= &sic <=	4712	then &newvarname = 	25	;
else if	4720	<= &sic <=	4729	then &newvarname = 	25	;
else if	4730	<= &sic <=	4739	then &newvarname = 	25	;
else if	4740	<= &sic <=	4749	then &newvarname = 	25	;
else if	4780	<= &sic <=	4780	then &newvarname = 	25	;
else if	4782	<= &sic <=	4782	then &newvarname = 	25	;
else if	4783	<= &sic <=	4783	then &newvarname = 	25	;
else if	4784	<= &sic <=	4784	then &newvarname = 	25	;
else if	4785	<= &sic <=	4785	then &newvarname = 	25	;
else if	4789	<= &sic <=	4789	then &newvarname = 	25	;
else if	5000	<= &sic <=	5000	then &newvarname = 	26	;
else if	5010	<= &sic <=	5015	then &newvarname = 	26	;
else if	5020	<= &sic <=	5023	then &newvarname = 	26	;
else if	5030	<= &sic <=	5039	then &newvarname = 	26	;
else if	5040	<= &sic <=	5042	then &newvarname = 	26	;
else if	5043	<= &sic <=	5043	then &newvarname = 	26	;
else if	5044	<= &sic <=	5044	then &newvarname = 	26	;
else if	5045	<= &sic <=	5045	then &newvarname = 	26	;
else if	5046	<= &sic <=	5046	then &newvarname = 	26	;
else if	5047	<= &sic <=	5047	then &newvarname = 	26	;
else if	5048	<= &sic <=	5048	then &newvarname = 	26	;
else if	5049	<= &sic <=	5049	then &newvarname = 	26	;
else if	5050	<= &sic <=	5059	then &newvarname = 	26	;
else if	5060	<= &sic <=	5060	then &newvarname = 	26	;
else if	5063	<= &sic <=	5063	then &newvarname = 	26	;
else if	5064	<= &sic <=	5064	then &newvarname = 	26	;
else if	5065	<= &sic <=	5065	then &newvarname = 	26	;
else if	5070	<= &sic <=	5078	then &newvarname = 	26	;
else if	5080	<= &sic <=	5080	then &newvarname = 	26	;
else if	5081	<= &sic <=	5081	then &newvarname = 	26	;
else if	5082	<= &sic <=	5082	then &newvarname = 	26	;
else if	5083	<= &sic <=	5083	then &newvarname = 	26	;
else if	5084	<= &sic <=	5084	then &newvarname = 	26	;
else if	5085	<= &sic <=	5085	then &newvarname = 	26	;
else if	5086	<= &sic <=	5087	then &newvarname = 	26	;
else if	5088	<= &sic <=	5088	then &newvarname = 	26	;
else if	5090	<= &sic <=	5090	then &newvarname = 	26	;
else if	5091	<= &sic <=	5092	then &newvarname = 	26	;
else if	5093	<= &sic <=	5093	then &newvarname = 	26	;
else if	5094	<= &sic <=	5094	then &newvarname = 	26	;
else if	5099	<= &sic <=	5099	then &newvarname = 	26	;
else if	5100	<= &sic <=	5100	then &newvarname = 	26	;
else if	5110	<= &sic <=	5113	then &newvarname = 	26	;
else if	5120	<= &sic <=	5122	then &newvarname = 	26	;
else if	5130	<= &sic <=	5139	then &newvarname = 	26	;
else if	5140	<= &sic <=	5149	then &newvarname = 	26	;
else if	5150	<= &sic <=	5159	then &newvarname = 	26	;
else if	5160	<= &sic <=	5169	then &newvarname = 	26	;
else if	5170	<= &sic <=	5172	then &newvarname = 	26	;
else if	5180	<= &sic <=	5182	then &newvarname = 	26	;
else if	5190	<= &sic <=	5199	then &newvarname = 	26	;
else if	5200	<= &sic <=	5200	then &newvarname = 	27	;
else if	5210	<= &sic <=	5219	then &newvarname = 	27	;
else if	5220	<= &sic <=	5229	then &newvarname = 	27	;
else if	5230	<= &sic <=	5231	then &newvarname = 	27	;
else if	5250	<= &sic <=	5251	then &newvarname = 	27	;
else if	5260	<= &sic <=	5261	then &newvarname = 	27	;
else if	5270	<= &sic <=	5271	then &newvarname = 	27	;
else if	5300	<= &sic <=	5300	then &newvarname = 	27	;
else if	5310	<= &sic <=	5311	then &newvarname = 	27	;
else if	5320	<= &sic <=	5320	then &newvarname = 	27	;
else if	5330	<= &sic <=	5331	then &newvarname = 	27	;
else if	5334	<= &sic <=	5334	then &newvarname = 	27	;
else if	5340	<= &sic <=	5349	then &newvarname = 	27	;
else if	5390	<= &sic <=	5399	then &newvarname = 	27	;
else if	5400	<= &sic <=	5400	then &newvarname = 	27	;
else if	5410	<= &sic <=	5411	then &newvarname = 	27	;
else if	5412	<= &sic <=	5412	then &newvarname = 	27	;
else if	5420	<= &sic <=	5429	then &newvarname = 	27	;
else if	5430	<= &sic <=	5439	then &newvarname = 	27	;
else if	5440	<= &sic <=	5449	then &newvarname = 	27	;
else if	5450	<= &sic <=	5459	then &newvarname = 	27	;
else if	5460	<= &sic <=	5469	then &newvarname = 	27	;
else if	5490	<= &sic <=	5499	then &newvarname = 	27	;
else if	5500	<= &sic <=	5500	then &newvarname = 	27	;
else if	5510	<= &sic <=	5529	then &newvarname = 	27	;
else if	5530	<= &sic <=	5539	then &newvarname = 	27	;
else if	5540	<= &sic <=	5549	then &newvarname = 	27	;
else if	5550	<= &sic <=	5559	then &newvarname = 	27	;
else if	5560	<= &sic <=	5569	then &newvarname = 	27	;
else if	5570	<= &sic <=	5579	then &newvarname = 	27	;
else if	5590	<= &sic <=	5599	then &newvarname = 	27	;
else if	5600	<= &sic <=	5699	then &newvarname = 	27	;
else if	5700	<= &sic <=	5700	then &newvarname = 	27	;
else if	5710	<= &sic <=	5719	then &newvarname = 	27	;
else if	5720	<= &sic <=	5722	then &newvarname = 	27	;
else if	5730	<= &sic <=	5733	then &newvarname = 	27	;
else if	5734	<= &sic <=	5734	then &newvarname = 	27	;
else if	5735	<= &sic <=	5735	then &newvarname = 	27	;
else if	5736	<= &sic <=	5736	then &newvarname = 	27	;
else if	5750	<= &sic <=	5799	then &newvarname = 	27	;
else if	5900	<= &sic <=	5900	then &newvarname = 	27	;
else if	5910	<= &sic <=	5912	then &newvarname = 	27	;
else if	5920	<= &sic <=	5929	then &newvarname = 	27	;
else if	5930	<= &sic <=	5932	then &newvarname = 	27	;
else if	5940	<= &sic <=	5940	then &newvarname = 	27	;
else if	5941	<= &sic <=	5941	then &newvarname = 	27	;
else if	5942	<= &sic <=	5942	then &newvarname = 	27	;
else if	5943	<= &sic <=	5943	then &newvarname = 	27	;
else if	5944	<= &sic <=	5944	then &newvarname = 	27	;
else if	5945	<= &sic <=	5945	then &newvarname = 	27	;
else if	5946	<= &sic <=	5946	then &newvarname = 	27	;
else if	5947	<= &sic <=	5947	then &newvarname = 	27	;
else if	5948	<= &sic <=	5948	then &newvarname = 	27	;
else if	5949	<= &sic <=	5949	then &newvarname = 	27	;
else if	5950	<= &sic <=	5959	then &newvarname = 	27	;
else if	5960	<= &sic <=	5969	then &newvarname = 	27	;
else if	5970	<= &sic <=	5979	then &newvarname = 	27	;
else if	5980	<= &sic <=	5989	then &newvarname = 	27	;
else if	5990	<= &sic <=	5990	then &newvarname = 	27	;
else if	5992	<= &sic <=	5992	then &newvarname = 	27	;
else if	5993	<= &sic <=	5993	then &newvarname = 	27	;
else if	5994	<= &sic <=	5994	then &newvarname = 	27	;
else if	5995	<= &sic <=	5995	then &newvarname = 	27	;
else if	5999	<= &sic <=	5999	then &newvarname = 	27	;
else if	5800	<= &sic <=	5819	then &newvarname = 	28	;
else if	5820	<= &sic <=	5829	then &newvarname = 	28	;
else if	5890	<= &sic <=	5899	then &newvarname = 	28	;
else if	7000	<= &sic <=	7000	then &newvarname = 	28	;
else if	7010	<= &sic <=	7019	then &newvarname = 	28	;
else if	7040	<= &sic <=	7049	then &newvarname = 	28	;
else if	7213	<= &sic <=	7213	then &newvarname = 	28	;
else if	6000	<= &sic <=	6000	then &newvarname = 	29	;
else if	6010	<= &sic <=	6019	then &newvarname = 	29	;
else if	6020	<= &sic <=	6020	then &newvarname = 	29	;
else if	6021	<= &sic <=	6021	then &newvarname = 	29	;
else if	6022	<= &sic <=	6022	then &newvarname = 	29	;
else if	6023	<= &sic <=	6024	then &newvarname = 	29	;
else if	6025	<= &sic <=	6025	then &newvarname = 	29	;
else if	6026	<= &sic <=	6026	then &newvarname = 	29	;
else if	6027	<= &sic <=	6027	then &newvarname = 	29	;
else if	6028	<= &sic <=	6029	then &newvarname = 	29	;
else if	6030	<= &sic <=	6036	then &newvarname = 	29	;
else if	6040	<= &sic <=	6059	then &newvarname = 	29	;
else if	6060	<= &sic <=	6062	then &newvarname = 	29	;
else if	6080	<= &sic <=	6082	then &newvarname = 	29	;
else if	6090	<= &sic <=	6099	then &newvarname = 	29	;
else if	6100	<= &sic <=	6100	then &newvarname = 	29	;
else if	6110	<= &sic <=	6111	then &newvarname = 	29	;
else if	6112	<= &sic <=	6113	then &newvarname = 	29	;
else if	6120	<= &sic <=	6129	then &newvarname = 	29	;
else if	6130	<= &sic <=	6139	then &newvarname = 	29	;
else if	6140	<= &sic <=	6149	then &newvarname = 	29	;
else if	6150	<= &sic <=	6159	then &newvarname = 	29	;
else if	6160	<= &sic <=	6169	then &newvarname = 	29	;
else if	6170	<= &sic <=	6179	then &newvarname = 	29	;
else if	6190	<= &sic <=	6199	then &newvarname = 	29	;
else if	6200	<= &sic <=	6299	then &newvarname = 	29	;
else if	6300	<= &sic <=	6300	then &newvarname = 	29	;
else if	6310	<= &sic <=	6319	then &newvarname = 	29	;
else if	6320	<= &sic <=	6329	then &newvarname = 	29	;
else if	6330	<= &sic <=	6331	then &newvarname = 	29	;
else if	6350	<= &sic <=	6351	then &newvarname = 	29	;
else if	6360	<= &sic <=	6361	then &newvarname = 	29	;
else if	6370	<= &sic <=	6379	then &newvarname = 	29	;
else if	6390	<= &sic <=	6399	then &newvarname = 	29	;
else if	6400	<= &sic <=	6411	then &newvarname = 	29	;
else if	6500	<= &sic <=	6500	then &newvarname = 	29	;
else if	6510	<= &sic <=	6510	then &newvarname = 	29	;
else if	6512	<= &sic <=	6512	then &newvarname = 	29	;
else if	6513	<= &sic <=	6513	then &newvarname = 	29	;
else if	6514	<= &sic <=	6514	then &newvarname = 	29	;
else if	6515	<= &sic <=	6515	then &newvarname = 	29	;
else if	6517	<= &sic <=	6519	then &newvarname = 	29	;
else if	6520	<= &sic <=	6529	then &newvarname = 	29	;
else if	6530	<= &sic <=	6531	then &newvarname = 	29	;
else if	6532	<= &sic <=	6532	then &newvarname = 	29	;
else if	6540	<= &sic <=	6541	then &newvarname = 	29	;
else if	6550	<= &sic <=	6553	then &newvarname = 	29	;
else if	6590	<= &sic <=	6599	then &newvarname = 	29	;
else if	6610	<= &sic <=	6611	then &newvarname = 	29	;
else if	6700	<= &sic <=	6700	then &newvarname = 	29	;
else if	6710	<= &sic <=	6719	then &newvarname = 	29	;
else if	6720	<= &sic <=	6722	then &newvarname = 	29	;
else if	6723	<= &sic <=	6723	then &newvarname = 	29	;
else if	6724	<= &sic <=	6724	then &newvarname = 	29	;
else if	6725	<= &sic <=	6725	then &newvarname = 	29	;
else if	6726	<= &sic <=	6726	then &newvarname = 	29	;
else if	6730	<= &sic <=	6733	then &newvarname = 	29	;
else if	6740	<= &sic <=	6779	then &newvarname = 	29	;
else if	6790	<= &sic <=	6791	then &newvarname = 	29	;
else if	6792	<= &sic <=	6792	then &newvarname = 	29	;
else if	6793	<= &sic <=	6793	then &newvarname = 	29	;
else if	6794	<= &sic <=	6794	then &newvarname = 	29	;
else if	6795	<= &sic <=	6795	then &newvarname = 	29	;
else if	6798	<= &sic <=	6798	then &newvarname = 	29	;
else if	6799	<= &sic <=	6799	then &newvarname = 	29	;
else if	4950	<= &sic <=	4959	then &newvarname = 	30	;
else if	4960	<= &sic <=	4961	then &newvarname = 	30	;
else if	4970	<= &sic <=	4971	then &newvarname = 	30	;
else if	4990	<= &sic <=	4991	then &newvarname = 	30	;
else &newvarname =30;
run;



proc format;
   value ff
	1="Food Products"
2="Beer and Liquor"
3="Tobacco Products"
4="Recreation"
5="Printing and Publishing"
6="Consumer Goods"
7="Apparel"
8="Healthcare, Medical Equip and Pharmaceuticals"
9="Chemicals"
10="Textiles"
11="Construction and Const. Materials"
12="Steel Works"
13="Fabricated Products"
14="Electrical Equipment"
15="Automobiles"
16="Aircraft, Ships and Equipment"
17="Precious Metals and Industrial Metal Mining"
18="Coal"
19="Petroleum and Natural Gas"
20="Utilities"
21="Communication"
22="Personal and Business Services"
23="Business Equipment"
24="Business Supplies and Shipping Containers"
25="Transportation"
26="Wholesale"
27="Retail"
28="Restaurants, Hotels & Motels"
29="Financial Institutions"
30="Other";
run;
%mend;




*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;
*CREATES FAMA-FRENCH 48 INDUSTRY CLASSIFICATIONS
*---------------------------------------------------------------------------------------------------------------------;
*---------------------------------------------------------------------------------------------------------------------;

%macro ff48(data=,newvarname=industry,sic=sic,out=&data);

data &out;
    set &data;
    &newvarname = 48;
if	100	<= &sic <=	199	then &newvarname = 	1	;
else	if		200	<=	&sic	<=	299	then	&newvarname	=	1	;
else	if		700	<=	&sic	<=	799	then	&newvarname	=	1	;
else	if		910	<=	&sic	<=	919	then	&newvarname	=	1	;
else	if		2048	<=	&sic	<=	2048	then	&newvarname	=	1	;
else	if		2000	<=	&sic	<=	2009	then	&newvarname	=	2	;
else	if		2010	<=	&sic	<=	2019	then	&newvarname	=	2	;
else	if		2020	<=	&sic	<=	2029	then	&newvarname	=	2	;
else	if		2030	<=	&sic	<=	2039	then	&newvarname	=	2	;
else	if		2040	<=	&sic	<=	2046	then	&newvarname	=	2	;
else	if		2050	<=	&sic	<=	2059	then	&newvarname	=	2	;
else	if		2060	<=	&sic	<=	2063	then	&newvarname	=	2	;
else	if		2070	<=	&sic	<=	2079	then	&newvarname	=	2	;
else	if		2090	<=	&sic	<=	2092	then	&newvarname	=	2	;
else	if		2095	<=	&sic	<=	2095	then	&newvarname	=	2	;
else	if		2098	<=	&sic	<=	2099	then	&newvarname	=	2	;
else	if		2064	<=	&sic	<=	2068	then	&newvarname	=	3	;
else	if		2086	<=	&sic	<=	2086	then	&newvarname	=	3	;
else	if		2087	<=	&sic	<=	2087	then	&newvarname	=	3	;
else	if		2096	<=	&sic	<=	2096	then	&newvarname	=	3	;
else	if		2097	<=	&sic	<=	2097	then	&newvarname	=	3	;
else	if		2080	<=	&sic	<=	2080	then	&newvarname	=	4	;
else	if		2082	<=	&sic	<=	2082	then	&newvarname	=	4	;
else	if		2083	<=	&sic	<=	2083	then	&newvarname	=	4	;
else	if		2084	<=	&sic	<=	2084	then	&newvarname	=	4	;
else	if		2085	<=	&sic	<=	2085	then	&newvarname	=	4	;
else	if		2100	<=	&sic	<=	2199	then	&newvarname	=	5	;
else	if		920	<=	&sic	<=	999	then	&newvarname	=	6	;
else	if		3650	<=	&sic	<=	3651	then	&newvarname	=	6	;
else	if		3652	<=	&sic	<=	3652	then	&newvarname	=	6	;
else	if		3732	<=	&sic	<=	3732	then	&newvarname	=	6	;
else	if		3930	<=	&sic	<=	3931	then	&newvarname	=	6	;
else	if		3940	<=	&sic	<=	3949	then	&newvarname	=	6	;
else	if		7800	<=	&sic	<=	7829	then	&newvarname	=	7	;
else	if		7830	<=	&sic	<=	7833	then	&newvarname	=	7	;
else	if		7840	<=	&sic	<=	7841	then	&newvarname	=	7	;
else	if		7900	<=	&sic	<=	7900	then	&newvarname	=	7	;
else	if		7910	<=	&sic	<=	7911	then	&newvarname	=	7	;
else	if		7920	<=	&sic	<=	7929	then	&newvarname	=	7	;
else	if		7930	<=	&sic	<=	7933	then	&newvarname	=	7	;
else	if		7940	<=	&sic	<=	7949	then	&newvarname	=	7	;
else	if		7980	<=	&sic	<=	7980	then	&newvarname	=	7	;
else	if		7990	<=	&sic	<=	7999	then	&newvarname	=	7	;
else	if		2700	<=	&sic	<=	2709	then	&newvarname	=	8	;
else	if		2710	<=	&sic	<=	2719	then	&newvarname	=	8	;
else	if		2720	<=	&sic	<=	2729	then	&newvarname	=	8	;
else	if		2730	<=	&sic	<=	2739	then	&newvarname	=	8	;
else	if		2740	<=	&sic	<=	2749	then	&newvarname	=	8	;
else	if		2770	<=	&sic	<=	2771	then	&newvarname	=	8	;
else	if		2780	<=	&sic	<=	2789	then	&newvarname	=	8	;
else	if		2790	<=	&sic	<=	2799	then	&newvarname	=	8	;
else	if		2047	<=	&sic	<=	2047	then	&newvarname	=	9	;
else	if		2391	<=	&sic	<=	2392	then	&newvarname	=	9	;
else	if		2510	<=	&sic	<=	2519	then	&newvarname	=	9	;
else	if		2590	<=	&sic	<=	2599	then	&newvarname	=	9	;
else	if		2840	<=	&sic	<=	2843	then	&newvarname	=	9	;
else	if		2844	<=	&sic	<=	2844	then	&newvarname	=	9	;
else	if		3160	<=	&sic	<=	3161	then	&newvarname	=	9	;
else	if		3170	<=	&sic	<=	3171	then	&newvarname	=	9	;
else	if		3172	<=	&sic	<=	3172	then	&newvarname	=	9	;
else	if		3190	<=	&sic	<=	3199	then	&newvarname	=	9	;
else	if		3229	<=	&sic	<=	3229	then	&newvarname	=	9	;
else	if		3260	<=	&sic	<=	3260	then	&newvarname	=	9	;
else	if		3262	<=	&sic	<=	3263	then	&newvarname	=	9	;
else	if		3269	<=	&sic	<=	3269	then	&newvarname	=	9	;
else	if		3230	<=	&sic	<=	3231	then	&newvarname	=	9	;
else	if		3630	<=	&sic	<=	3639	then	&newvarname	=	9	;
else	if		3750	<=	&sic	<=	3751	then	&newvarname	=	9	;
else	if		3800	<=	&sic	<=	3800	then	&newvarname	=	9	;
else	if		3860	<=	&sic	<=	3861	then	&newvarname	=	9	;
else	if		3870	<=	&sic	<=	3873	then	&newvarname	=	9	;
else	if		3910	<=	&sic	<=	3911	then	&newvarname	=	9	;
else	if		3914	<=	&sic	<=	3914	then	&newvarname	=	9	;
else	if		3915	<=	&sic	<=	3915	then	&newvarname	=	9	;
else	if		3960	<=	&sic	<=	3962	then	&newvarname	=	9	;
else	if		3991	<=	&sic	<=	3991	then	&newvarname	=	9	;
else	if		3995	<=	&sic	<=	3995	then	&newvarname	=	9	;
else	if		2300	<=	&sic	<=	2390	then	&newvarname	=	10	;
else	if		3020	<=	&sic	<=	3021	then	&newvarname	=	10	;
else	if		3100	<=	&sic	<=	3111	then	&newvarname	=	10	;
else	if		3130	<=	&sic	<=	3131	then	&newvarname	=	10	;
else	if		3140	<=	&sic	<=	3149	then	&newvarname	=	10	;
else	if		3150	<=	&sic	<=	3151	then	&newvarname	=	10	;
else	if		3963	<=	&sic	<=	3965	then	&newvarname	=	10	;
else	if		8000	<=	&sic	<=	8099	then	&newvarname	=	11	;
else	if		3693	<=	&sic	<=	3693	then	&newvarname	=	12	;
else	if		3840	<=	&sic	<=	3849	then	&newvarname	=	12	;
else	if		3850	<=	&sic	<=	3851	then	&newvarname	=	12	;
else	if		2830	<=	&sic	<=	2830	then	&newvarname	=	13	;
else	if		2831	<=	&sic	<=	2831	then	&newvarname	=	13	;
else	if		2833	<=	&sic	<=	2833	then	&newvarname	=	13	;
else	if		2834	<=	&sic	<=	2834	then	&newvarname	=	13	;
else	if		2835	<=	&sic	<=	2835	then	&newvarname	=	13	;
else	if		2836	<=	&sic	<=	2836	then	&newvarname	=	13	;
else	if		2800	<=	&sic	<=	2809	then	&newvarname	=	14	;
else	if		2810	<=	&sic	<=	2819	then	&newvarname	=	14	;
else	if		2820	<=	&sic	<=	2829	then	&newvarname	=	14	;
else	if		2850	<=	&sic	<=	2859	then	&newvarname	=	14	;
else	if		2860	<=	&sic	<=	2869	then	&newvarname	=	14	;
else	if		2870	<=	&sic	<=	2879	then	&newvarname	=	14	;
else	if		2890	<=	&sic	<=	2899	then	&newvarname	=	14	;
else	if		3031	<=	&sic	<=	3031	then	&newvarname	=	15	;
else	if		3041	<=	&sic	<=	3041	then	&newvarname	=	15	;
else	if		3050	<=	&sic	<=	3053	then	&newvarname	=	15	;
else	if		3060	<=	&sic	<=	3069	then	&newvarname	=	15	;
else	if		3070	<=	&sic	<=	3079	then	&newvarname	=	15	;
else	if		3080	<=	&sic	<=	3089	then	&newvarname	=	15	;
else	if		3090	<=	&sic	<=	3099	then	&newvarname	=	15	;
else	if		2200	<=	&sic	<=	2269	then	&newvarname	=	16	;
else	if		2270	<=	&sic	<=	2279	then	&newvarname	=	16	;
else	if		2280	<=	&sic	<=	2284	then	&newvarname	=	16	;
else	if		2290	<=	&sic	<=	2295	then	&newvarname	=	16	;
else	if		2297	<=	&sic	<=	2297	then	&newvarname	=	16	;
else	if		2298	<=	&sic	<=	2298	then	&newvarname	=	16	;
else	if		2299	<=	&sic	<=	2299	then	&newvarname	=	16	;
else	if		2393	<=	&sic	<=	2395	then	&newvarname	=	16	;
else	if		2397	<=	&sic	<=	2399	then	&newvarname	=	16	;
else	if		800	<=	&sic	<=	899	then	&newvarname	=	17	;
else	if		2400	<=	&sic	<=	2439	then	&newvarname	=	17	;
else	if		2450	<=	&sic	<=	2459	then	&newvarname	=	17	;
else	if		2490	<=	&sic	<=	2499	then	&newvarname	=	17	;
else	if		2660	<=	&sic	<=	2661	then	&newvarname	=	17	;
else	if		2950	<=	&sic	<=	2952	then	&newvarname	=	17	;
else	if		3200	<=	&sic	<=	3200	then	&newvarname	=	17	;
else	if		3210	<=	&sic	<=	3211	then	&newvarname	=	17	;
else	if		3240	<=	&sic	<=	3241	then	&newvarname	=	17	;
else	if		3250	<=	&sic	<=	3259	then	&newvarname	=	17	;
else	if		3261	<=	&sic	<=	3261	then	&newvarname	=	17	;
else	if		3264	<=	&sic	<=	3264	then	&newvarname	=	17	;
else	if		3270	<=	&sic	<=	3275	then	&newvarname	=	17	;
else	if		3280	<=	&sic	<=	3281	then	&newvarname	=	17	;
else	if		3290	<=	&sic	<=	3293	then	&newvarname	=	17	;
else	if		3295	<=	&sic	<=	3299	then	&newvarname	=	17	;
else	if		3420	<=	&sic	<=	3429	then	&newvarname	=	17	;
else	if		3430	<=	&sic	<=	3433	then	&newvarname	=	17	;
else	if		3440	<=	&sic	<=	3441	then	&newvarname	=	17	;
else	if		3442	<=	&sic	<=	3442	then	&newvarname	=	17	;
else	if		3446	<=	&sic	<=	3446	then	&newvarname	=	17	;
else	if		3448	<=	&sic	<=	3448	then	&newvarname	=	17	;
else	if		3449	<=	&sic	<=	3449	then	&newvarname	=	17	;
else	if		3450	<=	&sic	<=	3451	then	&newvarname	=	17	;
else	if		3452	<=	&sic	<=	3452	then	&newvarname	=	17	;
else	if		3490	<=	&sic	<=	3499	then	&newvarname	=	17	;
else	if		3996	<=	&sic	<=	3996	then	&newvarname	=	17	;
else	if		1500	<=	&sic	<=	1511	then	&newvarname	=	18	;
else	if		1520	<=	&sic	<=	1529	then	&newvarname	=	18	;
else	if		1530	<=	&sic	<=	1539	then	&newvarname	=	18	;
else	if		1540	<=	&sic	<=	1549	then	&newvarname	=	18	;
else	if		1600	<=	&sic	<=	1699	then	&newvarname	=	18	;
else	if		1700	<=	&sic	<=	1799	then	&newvarname	=	18	;
else	if		3300	<=	&sic	<=	3300	then	&newvarname	=	19	;
else	if		3310	<=	&sic	<=	3317	then	&newvarname	=	19	;
else	if		3320	<=	&sic	<=	3325	then	&newvarname	=	19	;
else	if		3330	<=	&sic	<=	3339	then	&newvarname	=	19	;
else	if		3340	<=	&sic	<=	3341	then	&newvarname	=	19	;
else	if		3350	<=	&sic	<=	3357	then	&newvarname	=	19	;
else	if		3360	<=	&sic	<=	3369	then	&newvarname	=	19	;
else	if		3370	<=	&sic	<=	3379	then	&newvarname	=	19	;
else	if		3390	<=	&sic	<=	3399	then	&newvarname	=	19	;
else	if		3400	<=	&sic	<=	3400	then	&newvarname	=	20	;
else	if		3443	<=	&sic	<=	3443	then	&newvarname	=	20	;
else	if		3444	<=	&sic	<=	3444	then	&newvarname	=	20	;
else	if		3460	<=	&sic	<=	3469	then	&newvarname	=	20	;
else	if		3470	<=	&sic	<=	3479	then	&newvarname	=	20	;
else	if		3510	<=	&sic	<=	3519	then	&newvarname	=	21	;
else	if		3520	<=	&sic	<=	3529	then	&newvarname	=	21	;
else	if		3530	<=	&sic	<=	3530	then	&newvarname	=	21	;
else	if		3531	<=	&sic	<=	3531	then	&newvarname	=	21	;
else	if		3532	<=	&sic	<=	3532	then	&newvarname	=	21	;
else	if		3533	<=	&sic	<=	3533	then	&newvarname	=	21	;
else	if		3534	<=	&sic	<=	3534	then	&newvarname	=	21	;
else	if		3535	<=	&sic	<=	3535	then	&newvarname	=	21	;
else	if		3536	<=	&sic	<=	3536	then	&newvarname	=	21	;
else	if		3538	<=	&sic	<=	3538	then	&newvarname	=	21	;
else	if		3540	<=	&sic	<=	3549	then	&newvarname	=	21	;
else	if		3550	<=	&sic	<=	3559	then	&newvarname	=	21	;
else	if		3560	<=	&sic	<=	3569	then	&newvarname	=	21	;
else	if		3580	<=	&sic	<=	3580	then	&newvarname	=	21	;
else	if		3581	<=	&sic	<=	3581	then	&newvarname	=	21	;
else	if		3582	<=	&sic	<=	3582	then	&newvarname	=	21	;
else	if		3585	<=	&sic	<=	3585	then	&newvarname	=	21	;
else	if		3586	<=	&sic	<=	3586	then	&newvarname	=	21	;
else	if		3589	<=	&sic	<=	3589	then	&newvarname	=	21	;
else	if		3590	<=	&sic	<=	3599	then	&newvarname	=	21	;
else	if		3600	<=	&sic	<=	3600	then	&newvarname	=	22	;
else	if		3610	<=	&sic	<=	3613	then	&newvarname	=	22	;
else	if		3620	<=	&sic	<=	3621	then	&newvarname	=	22	;
else	if		3623	<=	&sic	<=	3629	then	&newvarname	=	22	;
else	if		3640	<=	&sic	<=	3644	then	&newvarname	=	22	;
else	if		3645	<=	&sic	<=	3645	then	&newvarname	=	22	;
else	if		3646	<=	&sic	<=	3646	then	&newvarname	=	22	;
else	if		3648	<=	&sic	<=	3649	then	&newvarname	=	22	;
else	if		3660	<=	&sic	<=	3660	then	&newvarname	=	22	;
else	if		3690	<=	&sic	<=	3690	then	&newvarname	=	22	;
else	if		3691	<=	&sic	<=	3692	then	&newvarname	=	22	;
else	if		3699	<=	&sic	<=	3699	then	&newvarname	=	22	;
else	if		2296	<=	&sic	<=	2296	then	&newvarname	=	23	;
else	if		2396	<=	&sic	<=	2396	then	&newvarname	=	23	;
else	if		3010	<=	&sic	<=	3011	then	&newvarname	=	23	;
else	if		3537	<=	&sic	<=	3537	then	&newvarname	=	23	;
else	if		3647	<=	&sic	<=	3647	then	&newvarname	=	23	;
else	if		3694	<=	&sic	<=	3694	then	&newvarname	=	23	;
else	if		3700	<=	&sic	<=	3700	then	&newvarname	=	23	;
else	if		3710	<=	&sic	<=	3710	then	&newvarname	=	23	;
else	if		3711	<=	&sic	<=	3711	then	&newvarname	=	23	;
else	if		3713	<=	&sic	<=	3713	then	&newvarname	=	23	;
else	if		3714	<=	&sic	<=	3714	then	&newvarname	=	23	;
else	if		3715	<=	&sic	<=	3715	then	&newvarname	=	23	;
else	if		3716	<=	&sic	<=	3716	then	&newvarname	=	23	;
else	if		3792	<=	&sic	<=	3792	then	&newvarname	=	23	;
else	if		3790	<=	&sic	<=	3791	then	&newvarname	=	23	;
else	if		3799	<=	&sic	<=	3799	then	&newvarname	=	23	;
else	if		3720	<=	&sic	<=	3720	then	&newvarname	=	24	;
else	if		3721	<=	&sic	<=	3721	then	&newvarname	=	24	;
else	if		3723	<=	&sic	<=	3724	then	&newvarname	=	24	;
else	if		3725	<=	&sic	<=	3725	then	&newvarname	=	24	;
else	if		3728	<=	&sic	<=	3729	then	&newvarname	=	24	;
else	if		3730	<=	&sic	<=	3731	then	&newvarname	=	25	;
else	if		3740	<=	&sic	<=	3743	then	&newvarname	=	25	;
else	if		3760	<=	&sic	<=	3769	then	&newvarname	=	26	;
else	if		3795	<=	&sic	<=	3795	then	&newvarname	=	26	;
else	if		3480	<=	&sic	<=	3489	then	&newvarname	=	26	;
else	if		1040	<=	&sic	<=	1049	then	&newvarname	=	27	;
else	if		1000	<=	&sic	<=	1009	then	&newvarname	=	28	;
else	if		1010	<=	&sic	<=	1019	then	&newvarname	=	28	;
else	if		1020	<=	&sic	<=	1029	then	&newvarname	=	28	;
else	if		1030	<=	&sic	<=	1039	then	&newvarname	=	28	;
else	if		1050	<=	&sic	<=	1059	then	&newvarname	=	28	;
else	if		1060	<=	&sic	<=	1069	then	&newvarname	=	28	;
else	if		1070	<=	&sic	<=	1079	then	&newvarname	=	28	;
else	if		1080	<=	&sic	<=	1089	then	&newvarname	=	28	;
else	if		1090	<=	&sic	<=	1099	then	&newvarname	=	28	;
else	if		1100	<=	&sic	<=	1119	then	&newvarname	=	28	;
else	if		1400	<=	&sic	<=	1499	then	&newvarname	=	28	;
else	if		1200	<=	&sic	<=	1299	then	&newvarname	=	29	;
else	if		1300	<=	&sic	<=	1300	then	&newvarname	=	30	;
else	if		1310	<=	&sic	<=	1319	then	&newvarname	=	30	;
else	if		1320	<=	&sic	<=	1329	then	&newvarname	=	30	;
else	if		1330	<=	&sic	<=	1339	then	&newvarname	=	30	;
else	if		1370	<=	&sic	<=	1379	then	&newvarname	=	30	;
else	if		1380	<=	&sic	<=	1380	then	&newvarname	=	30	;
else	if		1381	<=	&sic	<=	1381	then	&newvarname	=	30	;
else	if		1382	<=	&sic	<=	1382	then	&newvarname	=	30	;
else	if		1389	<=	&sic	<=	1389	then	&newvarname	=	30	;
else	if		2900	<=	&sic	<=	2912	then	&newvarname	=	30	;
else	if		2990	<=	&sic	<=	2999	then	&newvarname	=	30	;
else	if		4900	<=	&sic	<=	4900	then	&newvarname	=	31	;
else	if		4910	<=	&sic	<=	4911	then	&newvarname	=	31	;
else	if		4920	<=	&sic	<=	4922	then	&newvarname	=	31	;
else	if		4923	<=	&sic	<=	4923	then	&newvarname	=	31	;
else	if		4924	<=	&sic	<=	4925	then	&newvarname	=	31	;
else	if		4930	<=	&sic	<=	4931	then	&newvarname	=	31	;
else	if		4932	<=	&sic	<=	4932	then	&newvarname	=	31	;
else	if		4939	<=	&sic	<=	4939	then	&newvarname	=	31	;
else	if		4940	<=	&sic	<=	4942	then	&newvarname	=	31	;
else	if		4800	<=	&sic	<=	4800	then	&newvarname	=	32	;
else	if		4810	<=	&sic	<=	4813	then	&newvarname	=	32	;
else	if		4820	<=	&sic	<=	4822	then	&newvarname	=	32	;
else	if		4830	<=	&sic	<=	4839	then	&newvarname	=	32	;
else	if		4840	<=	&sic	<=	4841	then	&newvarname	=	32	;
else	if		4880	<=	&sic	<=	4889	then	&newvarname	=	32	;
else	if		4890	<=	&sic	<=	4890	then	&newvarname	=	32	;
else	if		4891	<=	&sic	<=	4891	then	&newvarname	=	32	;
else	if		4892	<=	&sic	<=	4892	then	&newvarname	=	32	;
else	if		4899	<=	&sic	<=	4899	then	&newvarname	=	32	;
else	if		7020	<=	&sic	<=	7021	then	&newvarname	=	33	;
else	if		7030	<=	&sic	<=	7033	then	&newvarname	=	33	;
else	if		7200	<=	&sic	<=	7200	then	&newvarname	=	33	;
else	if		7210	<=	&sic	<=	7212	then	&newvarname	=	33	;
else	if		7214	<=	&sic	<=	7214	then	&newvarname	=	33	;
else	if		7215	<=	&sic	<=	7216	then	&newvarname	=	33	;
else	if		7217	<=	&sic	<=	7217	then	&newvarname	=	33	;
else	if		7219	<=	&sic	<=	7219	then	&newvarname	=	33	;
else	if		7220	<=	&sic	<=	7221	then	&newvarname	=	33	;
else	if		7230	<=	&sic	<=	7231	then	&newvarname	=	33	;
else	if		7240	<=	&sic	<=	7241	then	&newvarname	=	33	;
else	if		7250	<=	&sic	<=	7251	then	&newvarname	=	33	;
else	if		7260	<=	&sic	<=	7269	then	&newvarname	=	33	;
else	if		7270	<=	&sic	<=	7290	then	&newvarname	=	33	;
else	if		7291	<=	&sic	<=	7291	then	&newvarname	=	33	;
else	if		7292	<=	&sic	<=	7299	then	&newvarname	=	33	;
else	if		7395	<=	&sic	<=	7395	then	&newvarname	=	33	;
else	if		7500	<=	&sic	<=	7500	then	&newvarname	=	33	;
else	if		7520	<=	&sic	<=	7529	then	&newvarname	=	33	;
else	if		7530	<=	&sic	<=	7539	then	&newvarname	=	33	;
else	if		7540	<=	&sic	<=	7549	then	&newvarname	=	33	;
else	if		7600	<=	&sic	<=	7600	then	&newvarname	=	33	;
else	if		7620	<=	&sic	<=	7620	then	&newvarname	=	33	;
else	if		7622	<=	&sic	<=	7622	then	&newvarname	=	33	;
else	if		7623	<=	&sic	<=	7623	then	&newvarname	=	33	;
else	if		7629	<=	&sic	<=	7629	then	&newvarname	=	33	;
else	if		7630	<=	&sic	<=	7631	then	&newvarname	=	33	;
else	if		7640	<=	&sic	<=	7641	then	&newvarname	=	33	;
else	if		7690	<=	&sic	<=	7699	then	&newvarname	=	33	;
else	if		8100	<=	&sic	<=	8199	then	&newvarname	=	33	;
else	if		8200	<=	&sic	<=	8299	then	&newvarname	=	33	;
else	if		8300	<=	&sic	<=	8399	then	&newvarname	=	33	;
else	if		8400	<=	&sic	<=	8499	then	&newvarname	=	33	;
else	if		8600	<=	&sic	<=	8699	then	&newvarname	=	33	;
else	if		8800	<=	&sic	<=	8899	then	&newvarname	=	33	;
else	if		7510	<=	&sic	<=	7515	then	&newvarname	=	33	;
else	if		2750	<=	&sic	<=	2759	then	&newvarname	=	34	;
else	if		3993	<=	&sic	<=	3993	then	&newvarname	=	34	;
else	if		7218	<=	&sic	<=	7218	then	&newvarname	=	34	;
else	if		7300	<=	&sic	<=	7300	then	&newvarname	=	34	;
else	if		7310	<=	&sic	<=	7319	then	&newvarname	=	34	;
else	if		7320	<=	&sic	<=	7329	then	&newvarname	=	34	;
else	if		7330	<=	&sic	<=	7339	then	&newvarname	=	34	;
else	if		7340	<=	&sic	<=	7342	then	&newvarname	=	34	;
else	if		7349	<=	&sic	<=	7349	then	&newvarname	=	34	;
else	if		7350	<=	&sic	<=	7351	then	&newvarname	=	34	;
else	if		7352	<=	&sic	<=	7352	then	&newvarname	=	34	;
else	if		7353	<=	&sic	<=	7353	then	&newvarname	=	34	;
else	if		7359	<=	&sic	<=	7359	then	&newvarname	=	34	;
else	if		7360	<=	&sic	<=	7369	then	&newvarname	=	34	;
else	if		7370	<=	&sic	<=	7372	then	&newvarname	=	34	;
else	if		7374	<=	&sic	<=	7374	then	&newvarname	=	34	;
else	if		7375	<=	&sic	<=	7375	then	&newvarname	=	34	;
else	if		7376	<=	&sic	<=	7376	then	&newvarname	=	34	;
else	if		7377	<=	&sic	<=	7377	then	&newvarname	=	34	;
else	if		7378	<=	&sic	<=	7378	then	&newvarname	=	34	;
else	if		7379	<=	&sic	<=	7379	then	&newvarname	=	34	;
else	if		7380	<=	&sic	<=	7380	then	&newvarname	=	34	;
else	if		7381	<=	&sic	<=	7382	then	&newvarname	=	34	;
else	if		7383	<=	&sic	<=	7383	then	&newvarname	=	34	;
else	if		7384	<=	&sic	<=	7384	then	&newvarname	=	34	;
else	if		7385	<=	&sic	<=	7385	then	&newvarname	=	34	;
else	if		7389	<=	&sic	<=	7390	then	&newvarname	=	34	;
else	if		7391	<=	&sic	<=	7391	then	&newvarname	=	34	;
else	if		7392	<=	&sic	<=	7392	then	&newvarname	=	34	;
else	if		7393	<=	&sic	<=	7393	then	&newvarname	=	34	;
else	if		7394	<=	&sic	<=	7394	then	&newvarname	=	34	;
else	if		7396	<=	&sic	<=	7396	then	&newvarname	=	34	;
else	if		7397	<=	&sic	<=	7397	then	&newvarname	=	34	;
else	if		7399	<=	&sic	<=	7399	then	&newvarname	=	34	;
else	if		7519	<=	&sic	<=	7519	then	&newvarname	=	34	;
else	if		8700	<=	&sic	<=	8700	then	&newvarname	=	34	;
else	if		8710	<=	&sic	<=	8713	then	&newvarname	=	34	;
else	if		8720	<=	&sic	<=	8721	then	&newvarname	=	34	;
else	if		8730	<=	&sic	<=	8734	then	&newvarname	=	34	;
else	if		8740	<=	&sic	<=	8748	then	&newvarname	=	34	;
else	if		8900	<=	&sic	<=	8910	then	&newvarname	=	34	;
else	if		8911	<=	&sic	<=	8911	then	&newvarname	=	34	;
else	if		8920	<=	&sic	<=	8999	then	&newvarname	=	34	;
else	if		4220	<=	&sic	<=	4229	then	&newvarname	=	34	;
else	if		3570	<=	&sic	<=	3579	then	&newvarname	=	35	;
else	if		3680	<=	&sic	<=	3680	then	&newvarname	=	35	;
else	if		3681	<=	&sic	<=	3681	then	&newvarname	=	35	;
else	if		3682	<=	&sic	<=	3682	then	&newvarname	=	35	;
else	if		3683	<=	&sic	<=	3683	then	&newvarname	=	35	;
else	if		3684	<=	&sic	<=	3684	then	&newvarname	=	35	;
else	if		3685	<=	&sic	<=	3685	then	&newvarname	=	35	;
else	if		3686	<=	&sic	<=	3686	then	&newvarname	=	35	;
else	if		3687	<=	&sic	<=	3687	then	&newvarname	=	35	;
else	if		3688	<=	&sic	<=	3688	then	&newvarname	=	35	;
else	if		3689	<=	&sic	<=	3689	then	&newvarname	=	35	;
else	if		3695	<=	&sic	<=	3695	then	&newvarname	=	35	;
else	if		7373	<=	&sic	<=	7373	then	&newvarname	=	35	;
else	if		3622	<=	&sic	<=	3622	then	&newvarname	=	36	;
else	if		3661	<=	&sic	<=	3661	then	&newvarname	=	36	;
else	if		3662	<=	&sic	<=	3662	then	&newvarname	=	36	;
else	if		3663	<=	&sic	<=	3663	then	&newvarname	=	36	;
else	if		3664	<=	&sic	<=	3664	then	&newvarname	=	36	;
else	if		3665	<=	&sic	<=	3665	then	&newvarname	=	36	;
else	if		3666	<=	&sic	<=	3666	then	&newvarname	=	36	;
else	if		3669	<=	&sic	<=	3669	then	&newvarname	=	36	;
else	if		3670	<=	&sic	<=	3679	then	&newvarname	=	36	;
else	if		3810	<=	&sic	<=	3810	then	&newvarname	=	36	;
else	if		3812	<=	&sic	<=	3812	then	&newvarname	=	36	;
else	if		3811	<=	&sic	<=	3811	then	&newvarname	=	37	;
else	if		3820	<=	&sic	<=	3820	then	&newvarname	=	37	;
else	if		3821	<=	&sic	<=	3821	then	&newvarname	=	37	;
else	if		3822	<=	&sic	<=	3822	then	&newvarname	=	37	;
else	if		3823	<=	&sic	<=	3823	then	&newvarname	=	37	;
else	if		3824	<=	&sic	<=	3824	then	&newvarname	=	37	;
else	if		3825	<=	&sic	<=	3825	then	&newvarname	=	37	;
else	if		3826	<=	&sic	<=	3826	then	&newvarname	=	37	;
else	if		3827	<=	&sic	<=	3827	then	&newvarname	=	37	;
else	if		3829	<=	&sic	<=	3829	then	&newvarname	=	37	;
else	if		3830	<=	&sic	<=	3839	then	&newvarname	=	37	;
else	if		2520	<=	&sic	<=	2549	then	&newvarname	=	38	;
else	if		2600	<=	&sic	<=	2639	then	&newvarname	=	38	;
else	if		2670	<=	&sic	<=	2699	then	&newvarname	=	38	;
else	if		2760	<=	&sic	<=	2761	then	&newvarname	=	38	;
else	if		3950	<=	&sic	<=	3955	then	&newvarname	=	38	;
else	if		2440	<=	&sic	<=	2449	then	&newvarname	=	39	;
else	if		2640	<=	&sic	<=	2659	then	&newvarname	=	39	;
else	if		3220	<=	&sic	<=	3221	then	&newvarname	=	39	;
else	if		3410	<=	&sic	<=	3412	then	&newvarname	=	39	;
else	if		4000	<=	&sic	<=	4013	then	&newvarname	=	40	;
else	if		4040	<=	&sic	<=	4049	then	&newvarname	=	40	;
else	if		4100	<=	&sic	<=	4100	then	&newvarname	=	40	;
else	if		4110	<=	&sic	<=	4119	then	&newvarname	=	40	;
else	if		4120	<=	&sic	<=	4121	then	&newvarname	=	40	;
else	if		4130	<=	&sic	<=	4131	then	&newvarname	=	40	;
else	if		4140	<=	&sic	<=	4142	then	&newvarname	=	40	;
else	if		4150	<=	&sic	<=	4151	then	&newvarname	=	40	;
else	if		4170	<=	&sic	<=	4173	then	&newvarname	=	40	;
else	if		4190	<=	&sic	<=	4199	then	&newvarname	=	40	;
else	if		4200	<=	&sic	<=	4200	then	&newvarname	=	40	;
else	if		4210	<=	&sic	<=	4219	then	&newvarname	=	40	;
else	if		4230	<=	&sic	<=	4231	then	&newvarname	=	40	;
else	if		4240	<=	&sic	<=	4249	then	&newvarname	=	40	;
else	if		4400	<=	&sic	<=	4499	then	&newvarname	=	40	;
else	if		4500	<=	&sic	<=	4599	then	&newvarname	=	40	;
else	if		4600	<=	&sic	<=	4699	then	&newvarname	=	40	;
else	if		4700	<=	&sic	<=	4700	then	&newvarname	=	40	;
else	if		4710	<=	&sic	<=	4712	then	&newvarname	=	40	;
else	if		4720	<=	&sic	<=	4729	then	&newvarname	=	40	;
else	if		4730	<=	&sic	<=	4739	then	&newvarname	=	40	;
else	if		4740	<=	&sic	<=	4749	then	&newvarname	=	40	;
else	if		4780	<=	&sic	<=	4780	then	&newvarname	=	40	;
else	if		4782	<=	&sic	<=	4782	then	&newvarname	=	40	;
else	if		4783	<=	&sic	<=	4783	then	&newvarname	=	40	;
else	if		4784	<=	&sic	<=	4784	then	&newvarname	=	40	;
else	if		4785	<=	&sic	<=	4785	then	&newvarname	=	40	;
else	if		4789	<=	&sic	<=	4789	then	&newvarname	=	40	;
else	if		5000	<=	&sic	<=	5000	then	&newvarname	=	41	;
else	if		5010	<=	&sic	<=	5015	then	&newvarname	=	41	;
else	if		5020	<=	&sic	<=	5023	then	&newvarname	=	41	;
else	if		5030	<=	&sic	<=	5039	then	&newvarname	=	41	;
else	if		5040	<=	&sic	<=	5042	then	&newvarname	=	41	;
else	if		5043	<=	&sic	<=	5043	then	&newvarname	=	41	;
else	if		5044	<=	&sic	<=	5044	then	&newvarname	=	41	;
else	if		5045	<=	&sic	<=	5045	then	&newvarname	=	41	;
else	if		5046	<=	&sic	<=	5046	then	&newvarname	=	41	;
else	if		5047	<=	&sic	<=	5047	then	&newvarname	=	41	;
else	if		5048	<=	&sic	<=	5048	then	&newvarname	=	41	;
else	if		5049	<=	&sic	<=	5049	then	&newvarname	=	41	;
else	if		5050	<=	&sic	<=	5059	then	&newvarname	=	41	;
else	if		5060	<=	&sic	<=	5060	then	&newvarname	=	41	;
else	if		5063	<=	&sic	<=	5063	then	&newvarname	=	41	;
else	if		5064	<=	&sic	<=	5064	then	&newvarname	=	41	;
else	if		5065	<=	&sic	<=	5065	then	&newvarname	=	41	;
else	if		5070	<=	&sic	<=	5078	then	&newvarname	=	41	;
else	if		5080	<=	&sic	<=	5080	then	&newvarname	=	41	;
else	if		5081	<=	&sic	<=	5081	then	&newvarname	=	41	;
else	if		5082	<=	&sic	<=	5082	then	&newvarname	=	41	;
else	if		5083	<=	&sic	<=	5083	then	&newvarname	=	41	;
else	if		5084	<=	&sic	<=	5084	then	&newvarname	=	41	;
else	if		5085	<=	&sic	<=	5085	then	&newvarname	=	41	;
else	if		5086	<=	&sic	<=	5087	then	&newvarname	=	41	;
else	if		5088	<=	&sic	<=	5088	then	&newvarname	=	41	;
else	if		5090	<=	&sic	<=	5090	then	&newvarname	=	41	;
else	if		5091	<=	&sic	<=	5092	then	&newvarname	=	41	;
else	if		5093	<=	&sic	<=	5093	then	&newvarname	=	41	;
else	if		5094	<=	&sic	<=	5094	then	&newvarname	=	41	;
else	if		5099	<=	&sic	<=	5099	then	&newvarname	=	41	;
else	if		5100	<=	&sic	<=	5100	then	&newvarname	=	41	;
else	if		5110	<=	&sic	<=	5113	then	&newvarname	=	41	;
else	if		5120	<=	&sic	<=	5122	then	&newvarname	=	41	;
else	if		5130	<=	&sic	<=	5139	then	&newvarname	=	41	;
else	if		5140	<=	&sic	<=	5149	then	&newvarname	=	41	;
else	if		5150	<=	&sic	<=	5159	then	&newvarname	=	41	;
else	if		5160	<=	&sic	<=	5169	then	&newvarname	=	41	;
else	if		5170	<=	&sic	<=	5172	then	&newvarname	=	41	;
else	if		5180	<=	&sic	<=	5182	then	&newvarname	=	41	;
else	if		5190	<=	&sic	<=	5199	then	&newvarname	=	41	;
else	if		5200	<=	&sic	<=	5200	then	&newvarname	=	42	;
else	if		5210	<=	&sic	<=	5219	then	&newvarname	=	42	;
else	if		5220	<=	&sic	<=	5229	then	&newvarname	=	42	;
else	if		5230	<=	&sic	<=	5231	then	&newvarname	=	42	;
else	if		5250	<=	&sic	<=	5251	then	&newvarname	=	42	;
else	if		5260	<=	&sic	<=	5261	then	&newvarname	=	42	;
else	if		5270	<=	&sic	<=	5271	then	&newvarname	=	42	;
else	if		5300	<=	&sic	<=	5300	then	&newvarname	=	42	;
else	if		5310	<=	&sic	<=	5311	then	&newvarname	=	42	;
else	if		5320	<=	&sic	<=	5320	then	&newvarname	=	42	;
else	if		5330	<=	&sic	<=	5331	then	&newvarname	=	42	;
else	if		5334	<=	&sic	<=	5334	then	&newvarname	=	42	;
else	if		5340	<=	&sic	<=	5349	then	&newvarname	=	42	;
else	if		5390	<=	&sic	<=	5399	then	&newvarname	=	42	;
else	if		5400	<=	&sic	<=	5400	then	&newvarname	=	42	;
else	if		5410	<=	&sic	<=	5411	then	&newvarname	=	42	;
else	if		5412	<=	&sic	<=	5412	then	&newvarname	=	42	;
else	if		5420	<=	&sic	<=	5429	then	&newvarname	=	42	;
else	if		5430	<=	&sic	<=	5439	then	&newvarname	=	42	;
else	if		5440	<=	&sic	<=	5449	then	&newvarname	=	42	;
else	if		5450	<=	&sic	<=	5459	then	&newvarname	=	42	;
else	if		5460	<=	&sic	<=	5469	then	&newvarname	=	42	;
else	if		5490	<=	&sic	<=	5499	then	&newvarname	=	42	;
else	if		5500	<=	&sic	<=	5500	then	&newvarname	=	42	;
else	if		5510	<=	&sic	<=	5529	then	&newvarname	=	42	;
else	if		5530	<=	&sic	<=	5539	then	&newvarname	=	42	;
else	if		5540	<=	&sic	<=	5549	then	&newvarname	=	42	;
else	if		5550	<=	&sic	<=	5559	then	&newvarname	=	42	;
else	if		5560	<=	&sic	<=	5569	then	&newvarname	=	42	;
else	if		5570	<=	&sic	<=	5579	then	&newvarname	=	42	;
else	if		5590	<=	&sic	<=	5599	then	&newvarname	=	42	;
else	if		5600	<=	&sic	<=	5699	then	&newvarname	=	42	;
else	if		5700	<=	&sic	<=	5700	then	&newvarname	=	42	;
else	if		5710	<=	&sic	<=	5719	then	&newvarname	=	42	;
else	if		5720	<=	&sic	<=	5722	then	&newvarname	=	42	;
else	if		5730	<=	&sic	<=	5733	then	&newvarname	=	42	;
else	if		5734	<=	&sic	<=	5734	then	&newvarname	=	42	;
else	if		5735	<=	&sic	<=	5735	then	&newvarname	=	42	;
else	if		5736	<=	&sic	<=	5736	then	&newvarname	=	42	;
else	if		5750	<=	&sic	<=	5799	then	&newvarname	=	42	;
else	if		5900	<=	&sic	<=	5900	then	&newvarname	=	42	;
else	if		5910	<=	&sic	<=	5912	then	&newvarname	=	42	;
else	if		5920	<=	&sic	<=	5929	then	&newvarname	=	42	;
else	if		5930	<=	&sic	<=	5932	then	&newvarname	=	42	;
else	if		5940	<=	&sic	<=	5940	then	&newvarname	=	42	;
else	if		5941	<=	&sic	<=	5941	then	&newvarname	=	42	;
else	if		5942	<=	&sic	<=	5942	then	&newvarname	=	42	;
else	if		5943	<=	&sic	<=	5943	then	&newvarname	=	42	;
else	if		5944	<=	&sic	<=	5944	then	&newvarname	=	42	;
else	if		5945	<=	&sic	<=	5945	then	&newvarname	=	42	;
else	if		5946	<=	&sic	<=	5946	then	&newvarname	=	42	;
else	if		5947	<=	&sic	<=	5947	then	&newvarname	=	42	;
else	if		5948	<=	&sic	<=	5948	then	&newvarname	=	42	;
else	if		5949	<=	&sic	<=	5949	then	&newvarname	=	42	;
else	if		5950	<=	&sic	<=	5959	then	&newvarname	=	42	;
else	if		5960	<=	&sic	<=	5969	then	&newvarname	=	42	;
else	if		5970	<=	&sic	<=	5979	then	&newvarname	=	42	;
else	if		5980	<=	&sic	<=	5989	then	&newvarname	=	42	;
else	if		5990	<=	&sic	<=	5990	then	&newvarname	=	42	;
else	if		5992	<=	&sic	<=	5992	then	&newvarname	=	42	;
else	if		5993	<=	&sic	<=	5993	then	&newvarname	=	42	;
else	if		5994	<=	&sic	<=	5994	then	&newvarname	=	42	;
else	if		5995	<=	&sic	<=	5995	then	&newvarname	=	42	;
else	if		5999	<=	&sic	<=	5999	then	&newvarname	=	42	;
else	if		5800	<=	&sic	<=	5819	then	&newvarname	=	43	;
else	if		5820	<=	&sic	<=	5829	then	&newvarname	=	43	;
else	if		5890	<=	&sic	<=	5899	then	&newvarname	=	43	;
else	if		7000	<=	&sic	<=	7000	then	&newvarname	=	43	;
else	if		7010	<=	&sic	<=	7019	then	&newvarname	=	43	;
else	if		7040	<=	&sic	<=	7049	then	&newvarname	=	43	;
else	if		7213	<=	&sic	<=	7213	then	&newvarname	=	43	;
else	if		6000	<=	&sic	<=	6000	then	&newvarname	=	44	;
else	if		6010	<=	&sic	<=	6019	then	&newvarname	=	44	;
else	if		6020	<=	&sic	<=	6020	then	&newvarname	=	44	;
else	if		6021	<=	&sic	<=	6021	then	&newvarname	=	44	;
else	if		6022	<=	&sic	<=	6022	then	&newvarname	=	44	;
else	if		6023	<=	&sic	<=	6024	then	&newvarname	=	44	;
else	if		6025	<=	&sic	<=	6025	then	&newvarname	=	44	;
else	if		6026	<=	&sic	<=	6026	then	&newvarname	=	44	;
else	if		6027	<=	&sic	<=	6027	then	&newvarname	=	44	;
else	if		6028	<=	&sic	<=	6029	then	&newvarname	=	44	;
else	if		6030	<=	&sic	<=	6036	then	&newvarname	=	44	;
else	if		6040	<=	&sic	<=	6059	then	&newvarname	=	44	;
else	if		6060	<=	&sic	<=	6062	then	&newvarname	=	44	;
else	if		6080	<=	&sic	<=	6082	then	&newvarname	=	44	;
else	if		6090	<=	&sic	<=	6099	then	&newvarname	=	44	;
else	if		6100	<=	&sic	<=	6100	then	&newvarname	=	44	;
else	if		6110	<=	&sic	<=	6111	then	&newvarname	=	44	;
else	if		6112	<=	&sic	<=	6113	then	&newvarname	=	44	;
else	if		6120	<=	&sic	<=	6129	then	&newvarname	=	44	;
else	if		6130	<=	&sic	<=	6139	then	&newvarname	=	44	;
else	if		6140	<=	&sic	<=	6149	then	&newvarname	=	44	;
else	if		6150	<=	&sic	<=	6159	then	&newvarname	=	44	;
else	if		6160	<=	&sic	<=	6169	then	&newvarname	=	44	;
else	if		6170	<=	&sic	<=	6179	then	&newvarname	=	44	;
else	if		6190	<=	&sic	<=	6199	then	&newvarname	=	44	;
else	if		6300	<=	&sic	<=	6300	then	&newvarname	=	45	;
else	if		6310	<=	&sic	<=	6319	then	&newvarname	=	45	;
else	if		6320	<=	&sic	<=	6329	then	&newvarname	=	45	;
else	if		6330	<=	&sic	<=	6331	then	&newvarname	=	45	;
else	if		6350	<=	&sic	<=	6351	then	&newvarname	=	45	;
else	if		6360	<=	&sic	<=	6361	then	&newvarname	=	45	;
else	if		6370	<=	&sic	<=	6379	then	&newvarname	=	45	;
else	if		6390	<=	&sic	<=	6399	then	&newvarname	=	45	;
else	if		6400	<=	&sic	<=	6411	then	&newvarname	=	45	;
else	if		6500	<=	&sic	<=	6500	then	&newvarname	=	46	;
else	if		6510	<=	&sic	<=	6510	then	&newvarname	=	46	;
else	if		6512	<=	&sic	<=	6512	then	&newvarname	=	46	;
else	if		6513	<=	&sic	<=	6513	then	&newvarname	=	46	;
else	if		6514	<=	&sic	<=	6514	then	&newvarname	=	46	;
else	if		6515	<=	&sic	<=	6515	then	&newvarname	=	46	;
else	if		6517	<=	&sic	<=	6519	then	&newvarname	=	46	;
else	if		6520	<=	&sic	<=	6529	then	&newvarname	=	46	;
else	if		6530	<=	&sic	<=	6531	then	&newvarname	=	46	;
else	if		6532	<=	&sic	<=	6532	then	&newvarname	=	46	;
else	if		6540	<=	&sic	<=	6541	then	&newvarname	=	46	;
else	if		6550	<=	&sic	<=	6553	then	&newvarname	=	46	;
else	if		6590	<=	&sic	<=	6599	then	&newvarname	=	46	;
else	if		6610	<=	&sic	<=	6611	then	&newvarname	=	46	;
else	if		6200	<=	&sic	<=	6299	then	&newvarname	=	47	;
else	if		6700	<=	&sic	<=	6700	then	&newvarname	=	47	;
else	if		6710	<=	&sic	<=	6719	then	&newvarname	=	47	;
else	if		6720	<=	&sic	<=	6722	then	&newvarname	=	47	;
else	if		6723	<=	&sic	<=	6723	then	&newvarname	=	47	;
else	if		6724	<=	&sic	<=	6724	then	&newvarname	=	47	;
else	if		6725	<=	&sic	<=	6725	then	&newvarname	=	47	;
else	if		6726	<=	&sic	<=	6726	then	&newvarname	=	47	;
else	if		6730	<=	&sic	<=	6733	then	&newvarname	=	47	;
else	if		6740	<=	&sic	<=	6779	then	&newvarname	=	47	;
else	if		6790	<=	&sic	<=	6791	then	&newvarname	=	47	;
else	if		6792	<=	&sic	<=	6792	then	&newvarname	=	47	;
else	if		6793	<=	&sic	<=	6793	then	&newvarname	=	47	;
else	if		6794	<=	&sic	<=	6794	then	&newvarname	=	47	;
else	if		6795	<=	&sic	<=	6795	then	&newvarname	=	47	;
else	if		6798	<=	&sic	<=	6798	then	&newvarname	=	47	;
else	if		6799	<=	&sic	<=	6799	then	&newvarname	=	47	;
else	if		4950	<=	&sic	<=	4959	then	&newvarname	=	48	;
else	if		4960	<=	&sic	<=	4961	then	&newvarname	=	48	;
else	if		4970	<=	&sic	<=	4971	then	&newvarname	=	48	;
else	if		4990	<=	&sic	<=	4991	then	&newvarname	=	48	;
else &newvarname =48;
run;

%mend;



/* ********************************************************************************* */
/* ******************** W R D S   R E S E A R C H   M A C R O S ******************** */
/* ********************************************************************************* */
/* Summary   : Compute Market-Model Betas                                            */
/* Date      : January, 2011                                                         */
/* Author    : Rabih Moussawi                                                        */
/* Variables : - S: Monthly/Daily, defaults to Monthly, but s=d for CRSP Daily data  */
/*             - BEGDATE: Sample Start Date                                          */
/*             - ENDDATE: Sample End Date                                            */
/*             - WINDOW: Window of Estimation                                        */
/*             - MINWIN: Minimum Window of Estimation for non-missing betas          */
/*             - INDEX: Market Return Variable, with default Value-Weighted (VWRETD) */
/*             - OUTSET: Output Dataset Name (default names crsp_m or crsp_d)        */
/* ********************************************************************************* */
 
%MACRO BETA (S=m,START=01JAN2000,END=30JUN2001,WINDOW=36,MINWIN=12,INDEX=VWRETD,OUTSET=beta_&s.);
 
/* Check Series: Daily or Monthly and define datasets - Default is Monthly  */
%if &s=D %then %let s=d; %else %if &s ne d %then %let s=m;
%if (%sysfunc(libref(crsp))) %then %do;
  %let cs=/wrds/crsp/sasdata/;
  libname crsp ("&cs/m_stock","&cs/q_stock","&cs/a_stock");
%end;
%let sf = crsp.&s.sf ;
%let si = crsp.&s.si ;
 
options nonotes;
%put #### START. Computing Betas from &sf Using &WINDOW Estimation Window ;
data _crsp1 /view=_crsp1;
set &sf. ;
where "&START."D<=date<="&END."D;
keep permno date ret;
run;
 
proc sql;
create table _crsp2
as select a.*, b.&index, b.&index*(abs(a.ret)>=0) as X, a.ret*b.&index as XY,
  (abs(a.ret*b.&index)>=0) as count
from _crsp1 as a left join &si. as b
on a.date=b.date
order by a.permno, a.date;
quit;
 
proc expand data=_crsp2 out=_crsp3 method=none;
by permno;
id date;
convert X=X2      / transformout= (MOVUSS &WINDOW.);
convert X=X       / transformout= (MOVSUM &WINDOW.);
convert XY=XY     / transformout= (MOVSUM &WINDOW.);
convert ret=Y     / transformout= (MOVSUM &WINDOW.);
convert count=n   / transformout= (MOVSUM &WINDOW.);
quit;
run;
 
data &outset;
set _crsp3;
if n>=&MINWIN. then beta=(XY-X*Y/n) / (X2-(X**2)/n);
label beta = "Stock Beta";
label n = "Number of Observations used to compute Beta";
drop X X2 XY Y COUNT;
format beta comma8.2 ret &index percentn8.2;
run;
 
/* House Cleaning */
proc sql;
drop view _crsp1;
drop table _crsp2, _crsp3;
quit;
 
options notes;
%put #### DONE . Dataset &outset. Created! ;    %put ;
 
%MEND BETA;
 
/* ********************************************************************************* */
/* *************  Material Copyright Wharton Research Data Services  *************** */
/* ****************************** All Rights Reserved ****************************** */
/* ********************************************************************************* */


* Run rolling regressions provided by Michael D. Boldin from WRDS Data Services;

%macro rollingreg
(
data= ,
out_ds= ,
model_equation= ,
id= , date=date ,
start_date= ,
end_date= ,
freq=month, s=1, n=12,
regprint=noprint
);
%* Start with empty output data sets;
proc datasets nolist;
delete _all_ds _outest_ds;
run;
* Prepare input data for by-id-date use;
proc sort data=&data;
by &id &date;
run;
%* Set the 'by-id' variable;
%let by_id= ; *blank default, no by variable;
%if %length(&id) > 0 %then %let by_id= by &id;
%* Determine date range variables;
%if %lowcase(%substr(&date,1,4))= year %then %let year_date=1;
%else %let year_date=0;
%let sdate1 = &start_date;
%let sdate2 = &end_date;
%* Make start and end date if missing;
%if &start_date = %str() | &end_date = %str() %then %do;
proc sql noprint;
create table _dx1 as
select min(&date) as min_date, max(&date) as max_date
from &data where not missing(&date);
select min_date into : min_date from _dx1;
select max_date into : max_date from _dx1;
quit;
%end;
%* SDATE1 and SDATE2 put in sas date number form (1/1/1960=0);
%if &sdate1 = %str() %then %do;
%let sdate1= &min_date;
%end;
%else %do;
%if (%index(&sdate1,%str(-)) > 1) | (%index(&sdate1,%str(/)) > 1)
%then %let sdate1= %sysfunc(inputn(&sdate1,mmddyy10.));
%else %if ( %length(&sdate1)=7 )
%then %let sdate1= %sysfunc(inputn(01&sdate1,date9.));
%else %if ( %length(&sdate1)=8 | %length(&sdate1)=9 )
%then %let sdate1= %sysfunc(inputn(&sdate1,date9.));
%else %if ( %length(&sdate1)=4 )
%then %let sdate1= %sysfunc(inputn(01JAN&sdate1,date9.));
%if &year_date=1 %then %let sdate1=%sysfunc(year(&sdate1));
%end;
%if &sdate2 = %str() %then %do;
%let sdate2= &max_date;
%end;
%else %do;
%if (%index(&sdate2,%str(-)) > 1) | (%index(&sdate2,%str(/)) > 1)
%then %let sdate2= %sysfunc(inputn(&sdate2,mmddyy10.));
%else %if ( %length(&sdate2)=7 ) %then %do;
%let sdate2= %sysfunc(inputn(01&sdate2,date9.));
%let sdate2= %sysfunc(intnx(month,&sdate2,0,end));
%end;
%else %if ( %length(&sdate2)=8 | %length(&sdate2)=9 )
%then %let sdate2= %sysfunc(inputn(&sdate2,date9.));
%else %if ( %length(&sdate2)=4 )
%then %let sdate2= %sysfunc(inputn(31DEC&sdate2,date9.));
%if &year_date=1 %then %let sdate2=%sysfunc(year(&sdate2));
%end;
%*Determine loop frequency parameters;
%if %eval(&n)= 0 %then %let n= &s;
%* if n blank use 1 period (=&s) assumption;
%if &year_date=1 %then %let freq=year;
%* year frequency case;
%put Date variable: &date year_date: &year_date;
%put Start and end dates: &start_date &end_date // &sdate1 &sdate2;
%if &year_date=0 %then
%put %sysfunc(putn(&sdate1,date9.)) %sysfunc(putn(&sdate2,date9.));
%put Freq: &freq s: &s n: &n;
%* Preliminary date setting for each iteration/loop;
%* First end date (idate2) is n periods after the start date;
%if &year_date=1 %then %let idate2= %eval(&sdate1+(&n-1));
%else %let idate2= %sysfunc(intnx(&freq,&sdate1,(&n-1),end));
%if &year_date=0 %then %let idate1= %sysfunc(intnx(&freq,&idate2,-&n+1,begin));
%else %let idate1= %eval(&idate2-&n+1);
%put First loop: &idate1 -- &idate2;
%put Loop through: &sdate2;
%if (&idate2 > &sdate2) %then %do;
%* Dates are not acceptable-- show problem, do not run loop;
%put PROBLEM-- end date for loop exceeds range : ( &idate2 > &sdate2 );
%end;
%else %do; *Dates are accepted-- run loops;
%let jj=0;
%do %while(&idate2 <= &sdate2);
%let jj=%eval(&jj+1);
%*Define loop start date (idate1) based on inherited end date (idate2);
%if &year_date=0 %then %do;
%let idate1= %sysfunc(intnx(&freq,&idate2,-&n+1,begin));
%let date1c= %sysfunc(putn(&idate1,date9.));
%let date2c= %sysfunc(putn(&idate2,date9.));
%end;
%if &year_date=1 %then %do;
%let idate1= %eval(&idate2-&n+1);
%let date1c= &idate1;
%let date2c= &idate2;
%end;
%let idate1= %sysfunc(max(&sdate1,&idate1));
%put Loop: &jj -- &date1c &date2c;
%put &jj -- &idate1 &idate2;
proc datasets nolist;
delete _outest_ds;
run;
%***** analysis code here -- for each loop;
%* noprint to just make output set;
%let noprint= noprint;
%if %upcase(�print) = yes | %upcase(�print) = print %then %let noprint= ;
proc reg data=&data
outest=_outest_ds edf
&noprint;
where &date between &idate1 and &idate2;
model &model_equation;
&by_id;
run;
%* Add loop date range variables to output set;
data _outest_ds;
set _outest_ds;
regobs= _p_ + _edf_; %* number of observations in regression;
date1= &idate1;
date2= &idate2;
%if &year_date=0 %then format date1 date2 date9.;
run;
%* Append results;
proc datasets nolist;
append base=_all_ds data=_outest_ds;
run;
%* Set next loop end date;
%if &year_date=0 %then %let idate2= %sysfunc(intnx(&freq,&idate2,&s,end));
%else %if &year_date=1 %then %let idate2= %eval(&idate2+&s);
%end; *% end of loop;
%* Save outout set to desired location;
data &out_ds;
set _all_ds;
run;
proc sort data=&out_ds;
by &id date2;
run;
%end; %* end for date check pass section;
%mend;

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EXAMPLE USE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*
***************************************************
* Run Rolling Regression using CRSP Monthly Stock data;
%include �rollingreg.sas�;
libname proj �.�;
*Prepare stock return data set for selected PERMNOs;
data proj.m1;
set crsp.msf (keep=permno date ret prc vol shrout);
where permno in (10107, 11081, 12490, 14593, 14656)
and year(date) >= 2005;
run;
*Add market return to each PERMNO block;
proc sql;
create table proj.m1 as
select a.*, b.vwretd
from proj.m1 as a
left join crsp.msi as b
on a.date=b.date
order by a.permno, a.date;
quit;


* Call macro;
%rollingreg(
data=proj.m1, out_ds=proj.rr1,
id=permno, date=date,
model_equation= ret= vwretd,
start_date= 1-1-2002, end_date= 12-31-2005,
freq=month, s=1, n=36);
* Show results;
proc print data=proj.rr1 (rename= (vwretd=beta));
by permno;
id date1 date2;
var rmse intercept beta regobs;
run;
*/
