Hi PGStats, Unfortunately, I am still struggling with the codes you supplied (please pardon my basic SAS knowledge). I am using the data-set approach because I have already created a data-set from my main data file. I have over a thousand observations, I don't think the 'datalines approach' would work well for me. However, I still have lots of errors in the log file. I am not too sure what is wrong. See the modified code I used below: data xxx; set xx; input Date :mmddyy. X1; format date yymmdd10.; proc sql; create table test as select a.date as middate, b.date > a.date as period, b.date, b.x1 from have as a inner join have as b on b.date between intnx('day',a.date,-30) and intnx('day',a.date,30) and a.date ne b.date group by middate having count(distinct period) = 2 order by middate, date; quit; ods select none; proc ttest data=test plots=none; ods output ttests=tt; by middate; class period; var x1; run; ods select all; proc print data=tt; run; See some errors from log file: ERROR: No DATALINES or INFILE statement. NOTE: The SAS System stopped processing this step because of errors. ERROR: Variable MIDDATE not found. ERROR: File WORK.TT.DATA does not exist
... View more