Any advice on how I can modify this problem code line below to get my datasets named without error?
I have a dataset where I want to match treatment firms (4400) with about 100,000 control firms by 48 industries and 14 years, then nearest size without replacement. My method below may be a bit clunky, but I am learning as I go. I am splitting the treatment and control datasets into 48x14 groups, (after this I will try to run nearest match without replacement code through some type of loop).
I have already used a variant of the below hash code to make 48 datasets out1...out48. Now I am attempting to further subset each of these 48 datasets into the 14 years through using the below code. I am receiving an error dataset creation line, where I am trying to create 48x14 datasets named out12004, out22004, out32004. . .out482013
Problem code line (about 2/3 down the code below): hh.output (dataset: 'out'||&i||put(year, best.-L)) ;
The SAS errors look like this:
ERROR: The value OUT 12004 is not a valid SAS name.
ERROR: An error has occurred during instance method OM_OUTPUT(505) of "DATASTEP.HASH".
Here is the full code (modified from Is it possible to loop over SAS datasets? andSUGI30 paper 236-30
%MACRO process_datasets(mdataset);
data &mdataset.;
set &mdataset.;
data _null_ ;
dcl hash hoh (ordered: 'a') ;
dcl hiter hih ('hoh' ) ;
hoh.definekey ('year' ) ;
hoh.definedata ('year', 'hh' ) ;
hoh.definedone () ;
dcl hash hh () ;
do _n_ = 1 by 1 until ( eof ) ;
set out&i. end = eof ;
if hoh.find () ne 0 then do ;
hh = _new_ hash (ordered: 'a') ;
hh.definekey ('industry','cik', 'year', '_n_') ;
hh.definedata ('industry','cik','year','eventdat', 'at', 'roa') ;
hh.definedone () ;
hoh.replace () ;
end ;
hh.replace() ;
end ;
do rc = hih.next () by 0 while ( rc = 0 ) ;
hh.output (dataset: '_'||&i||put(year, best.-L)) ;
rc = hih.next() ;
end ;
stop ;
run;
data _null_;
file 'tmp.csv' mod dsd dlm=','; *saving everything to the same file;
set &mdataset.;
put (_all_) (+0);
run;
%MEND process_datasets;
%MACRO loop_through_all;
%DO i = 1 %to 48;
%process_datasets(out&i.);
%END;
%MEND loop_through_all;