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.

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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