Hi Jim, Thank you so much for the help! And thank you for your patience with a new user. Here is all logs I have in log window. The code I got is from website posted by others. I guess it worked with others. 306 data QDC.temp1;set temp1;run;
NOTE: There were 236480 observations read from the data set WORK.TEMP1.
NOTE: The data set QDC.TEMP1 has 236480 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.66 seconds
cpu time 0.04 seconds
307
308 proc sort data=temp1; by year;run;
NOTE: Input data set is already sorted, no sorting done.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
309
310 %macro loop(year, nfirms);
311 OPTIONS MCOMPILENOTE=NOAUTOCALL;
312 OPTIONS SYMBOLGEN;
313 OPTIONS MPRINT;
314 /* Loop by firm &i for year &year. This will generate a dataset of
314! firm i-j AcctComp for each year. */
315
316 data temp1a; set temp1; if year(datadate1)=&year;
317 proc sort; by gvkey1;
318
319 data nfirms; set temp1a;
320 keep gvkey1;
321 proc sort nodupkey; by gvkey1;
322
323 data nfirms; set nfirms; id = _N_;
324
325 data temp1a; merge temp1a nfirms; by gvkey1;
326
327 %do i= 1 %to &nfirms;
328
329 data est1; set temp1a;
330 proc sort nodupkey; by gvkey1;
331
332 data est2; set temp1a; if id = &i;
333
334 PROC SQL;
335 CREATE TABLE est2 AS SELECT
336 est2.*, est1.gvkey1 AS gvkey_j, est1.a_i AS a_j, est1.b_i AS b_j
337 FROM est2 LEFT JOIN est1
338 ON est2.gvkey1 ~= est1.gvkey1
339 AND est2.sic2 = est1.sic2;
340 QUIT;
341
342 data est2; set est2;
343 a_dif = a_i - a_j;
344 b_dif = b_i - b_j;
345 drop a_i a_j b_i b_j;
346
347 proc sort; by gvkey1 datadate1 fqenddt1 datacqtr1 gvkey_j;
348
349 data est2; set est2;
350
351 proc sort; by gvkey1 datadate1 fqenddt1 datacqtr1 gvkey_j fqenddt;
352
353 data est2; set est2;
354 error = ABS(a_dif + bhr * b_dif);
355
356 proc sort; by gvkey1 datadate1 gvkey_j fqenddt;
357
358 PROC UNIVARIATE NOPRINT; by gvkey1 datadate1 gvkey_j;
359 VAR error ;
360 OUTPUT OUT = univ N=n MEAN = me_error ;
361
362 data univ; set univ;
363 acctcomp = -1 * me_error*100;
364 acctcomp = round(acctcomp, 0.001);
365
366 rename gvkey1 = gvkey_i;
367 rename datadate1 = datadate_i;
368
369 if not missing (acctcomp);
370 if 14 <= n <= 16;
371
372 drop me_error n;
373
374 PROC APPEND BASE = final data = univ; RUN;
375
376 %end ;
377
378 data QDC.acctcomp&year; set final;
379
380 proc sort; by gvkey_i datadate_i gvkey_j;
381
382 %mend loop;
NOTE: The macro LOOP completed compilation without errors.
30 instructions 1888 bytes.
383 run;
... View more