Ok Here is Plan A dataset
PLAN | REQUIREMENT | LINE# | CDATE |
A | RED | 1 | C024 |
B | YELLOW | 2 | C025 |
C | BLUE | 3 | C026 |
D | GREEN | 4 | C027 |
Ok Here is Plan B dataset
PLAN | REQUIREMENT | LINE# | CDATE |
A | RED | 1 | C024 |
B | YELLOW | 2 | C026 |
C | BLUE | 3 | C026 |
D | GREEN | 4 | C028 |
When I merge the datasets together, I only want it to populate the lines that have changed. This is the end result that I want
PLAN | REQUIREMENT | LINE# | CDATE |
B | YELLOW | 2 | C026 |
D | GREEN | 4 | C028 |
Can someone please assist? Thank you.
Data want;
Merge plan_A (in=x) plan_B (in=y);
By plan requirement line cdate;
If x=0 and y=1;
Run;
NB : your datasets need to be sorted by plan requirement line cdate
data plana;
input PLAN $ REQUIREMENT $ LINE CDATE $;
cards;
A RED 1 C024
B YELLOW 2 C025
C BLUE 3 C026
D GREEN 4 C027
;
run;
data planb;
input PLAN $ REQUIREMENT $ LINE CDATE $;
cards;
A RED 1 C024
B YELLOW 2 C026
C BLUE 3 C026
D GREEN 4 C028
;
run;
Proc SQl;
Create table want as
select * from plana
except
select * from planb;
Quit;
Data want;
Merge plan_A (in=x) plan_B (in=y);
By plan requirement line cdate;
If x=0 and y=1;
Run;
NB : your datasets need to be sorted by plan requirement line cdate
Thank you.
data a;
input PLAN $ REQUIREMENT $ LINE CDATE $;
datalines;
A RED 1 C024
B YELLOW 2 C025
C BLUE 3 C026
D GREEN 4 C027
;
data b;
input PLAN $ REQUIREMENT $ LINE CDATE $;
datalines;
A RED 1 C024
B YELLOW 2 C026
C BLUE 3 C026
D GREEN 4 C028
;
data want(drop=_: rc);
if _N_=1 then do;
declare hash h(dataset:'a(rename=cdate=_cdate');
h.definekey('plan', 'requirement', 'line');
h.definedata('_cdate');
h.definedone();
end;
set b;
length _cdate $ 8;
rc=h.find();
if cdate ne _cdate;
run;
Result:
PLAN REQUIREMENT LINE CDATE B YELLOW 2 C026 D GREEN 4 C028
Thank you!
What is your definition of changed? Do you just want to pick the observations that are in PLANB and not in PLANA?
proc sql;
create table want as
select * from planb
except
select * from plana
;
quit;
@kfbaker0206 wrote:
Ok Here is Plan A dataset
PLAN REQUIREMENT LINE# CDATE A RED 1 C024 B YELLOW 2 C025 C BLUE 3 C026 D GREEN 4 C027 Ok Here is Plan B dataset
PLAN REQUIREMENT LINE# CDATE A RED 1 C024 B YELLOW 2 C026 C BLUE 3 C026 D GREEN 4 C028
When I merge the datasets together, I only want it to populate the lines that have changed. This is the end result that I want
PLAN REQUIREMENT LINE# CDATE B YELLOW 2 C026 D GREEN 4 C028
Can someone please assist? Thank you.
Merge in SAS usually means to combine data sets by rows in some fashion. Please be aware of that as you can get very odd suggestions if there isn't any actual input data and desired shared by misuse of "merge".
Since your requirement does not combine the data then that is not typically a merge.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.