This code creates earnings surprise measurement and replicates post-earnings announcement drift with I/B/E/S, Compustat, and CRSP datasets. I follow the code given by WRDS (see the article here) and write the stata code from the original SAS code. After the merge, the final sample contains 410, 966 firm-quarters with non-missing information in all three datasets from 1983Q3 to 2022Q1.