datastep - SAS - Compare observation to previous observations? -
i have following data:
acct date 11111 01/01/2014 11111 01/01/2014 11111 02/02/2014 22222 01/01/2014 22222 01/01/2014 33333 01/01/2013 33333 03/03/2014 44444 01/01/2014 44444 01/01/2014 44444 01/01/2014
what best way accomplish following in sas? want compare dates each acct number , return records accts there @ least 1 date doesn't match.
so dataset above, want end following:
acct date 11111 01/01/2014 11111 01/01/2014 11111 02/02/2014 33333 01/01/2013 33333 03/03/2014
something work. sort data acct/date if not already, check each last.date
row. if first last.date
row not last.acct
, set of rows respondent needs output. here output 1 row per date/acct combination:
data want; set have; acct date; if (last.date) , not (last.acct) do; flg=1; output; end; else if last.date , flg=1 output; else if first.acct flg=0; run;
if need rows, need either take above , merge original, or dow loop:
data want; _n_=1 1 until (last.acct); set have; acct date; if (last.date) , not (last.acct) do; flg=1; end; end; _t_ = 1 1 until (last.acct); set have; acct date; if flg=1 output; end; run;
Comments
Post a Comment