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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.