Date: Sun, 1 Mar 2009 23:31:43 -0800
Reply-To: cnevin <chaitanya.sas@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: cnevin <chaitanya.sas@GMAIL.COM>
Organization: http://groups.google.com
Subject: Flaging the Incremental Data
Content-Type: text/plain; charset=ISO-8859-1
Dear All,
I've two datasets (OLD & NEW) to compare and create an incremental
dataset of New and Updated records (ie., only the difference between
the two data). Also need to flag those records in a new variable as
noted below.
New or Updated data can be:
1) a new record added where the value of variable 'si' is NEW (should
be flaged as NN).
2) a new record added to an existing value in variable 'si' (flaged as
NE).
3) a record modified (data correction) to an existing value of
variable 'si' (MD).
data old;
input si x y z a b c;
cards;
1 12 23 34 45 56 67
2 78 89 90 12 23 34
3 45 56 67 78 89 90
4 09 98 87 76 65 54
5 43 32 21 09 98 87
6 76 65 54 43 32 21
;
run;
data new;
input si x y z a b c;
cards;
1 12 23 34 45 56 67
2 78 89 90 12 23 34
3 45 56 67 89 78 90
4 09 98 87 76 65 54
4 54 65 76 87 98 09
5 43 32 21 09 98 87
6 76 65 54 43 32 21
7 01 92 83 74 65 56
8 10 29 38 47 56 65
;
In the NEW dataset, I've added
2 completely new records (for variable si 7 & 8)
1 new record to an existing variable si 4.
1 record modified (data correction) to an existing variable si 3.
With the proc step below, I can get the incremental dataset (INC) of 4
new and updated records :
proc sql;
create table INC as (select si, x, y, z, a, b, c from new
except
select si, x, y, z, a, b, c from old);
quit;
Now my query is to have flags in a new variable for these 4 records as
below:
si x y z a b c flg
3 45 56 67 78 89 90 MD
4 54 65 76 87 98 09 NE
7 01 92 83 74 65 56 NN
8 10 29 38 47 56 65 NN
Awaiting your response.
Best regards,
Chris Nevin