BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kfbaker0206
Fluorite | Level 6

Ok Here is Plan A dataset

PLANREQUIREMENTLINE#CDATE
ARED1C024
BYELLOW2C025
CBLUE3C026
DGREEN4C027

Ok Here is Plan B dataset

PLANREQUIREMENTLINE#CDATE
ARED1C024
BYELLOW2C026
CBLUE3C026
DGREEN4C028

 

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

PLANREQUIREMENTLINE#CDATE
BYELLOW2C026
DGREEN4C028

 

Can someone please assist? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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

View solution in original post

7 REPLIES 7
r_behata
Barite | Level 11
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;
ed_sas_member
Meteorite | Level 14

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

kfbaker0206
Fluorite | Level 6

Thank you.

PeterClemmensen
Tourmaline | Level 20
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 
kfbaker0206
Fluorite | Level 6

Thank you!

Tom
Super User Tom
Super User

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;
ballardw
Super User

@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.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 11906 views
  • 0 likes
  • 6 in conversation