@Jahanzaib:
Two comments on your topic.
First, we often set up SIC to Fame French conversions as functions, rather than statement groups. More about that later.
Array Lookup:
Second, we use array lookup for these conversions. In your case (which doesn't include all the SIC codes ours FF12 does), it would be:
data want;
array s_to_ff12 {100:7379} _temporary_ (900*1,1520*.,70*3,250*.,60*5,100*4,840*.,
20*10,130*.,10*2,800*.,100*7,50*8,
50*.,1000*9,1000*11,370*.,10*6);
if 100<=sicc<=7379 then ff12=sic_to_ff12{sicc};
else ff12=12;
I've rearranged the list by SIC code, rather than FF12 as in your program. This allows the parenthesized list of values to populate the FF12 codes for every element in the S_TO_FF12 array, i.e. SIC from 100 to 7379. For example, it starts out with 900 1's (for sic 100-999), then 1520 missings (sic 1000-2519), etc. Then just ask for the array element corresponding to the SIC code. Faster, and neater than a series of IF THEN ... ELSE, or even SELECT groups.
Good place for a function:
Neater still, if you do a one-time compile and store a function named S_to_FF12 in your MYLIB library in a MYUTILS catalog you could use that function in any subsequent use of sas, without re-compiling. You don't even have to construct the array anymore.
As long as you have an options statement like:
options cmplib=(mylib.myutils);
telling SAS where to look for user-defined functions, then you simply need one statement:
ff12=s_to_ff12(sicc);
And you could also use this function to subset data via a WHERE expression, as in
PROC REG data=mylib.mydata;
where s_to_ff12(sicc) =2;
model ret=sp500 + factor1 +factor2 + factor3;
or
DATA new;
set have;
where s_to_ff12(sicc) in (2,4,6);
So, here's how to make the function, using the array logic above:
proc fcmp outlib=mylib.ffutils.funcs;
deletefunc s_to_ff12;
quit;
proc fcmp outlib=mylib.ffutils.funcs;
function s_to_ff12(_sic);
array ff {100:7379} _temporary_ (900*1,1520*.,70*3,250*.,60*5,100*4,840*.,
20*10,130*.,10*2,800*.,100*7,50*8,
50*.,1000*9,1000*11,370*.,10*6);
if (100<=_sic<=7379) then return(ff{_sic});
else return(.);
endsub;
quit;
That's it.
regards,
Mark
... View more