BookmarkSubscribeRSS Feed
adamsfam1
Calcite | Level 5


Hello,

I'm a relatively new SAS user.  I'm trying to write a data step for the following condition:

I have 2 data sets.  One contains old items.  The other new items.  I need to create a file that show the items on the new file that are not on the old file.

What is the best way to go about this?

6 REPLIES 6
Reeza
Super User

Usually SQL.

But a data step merge works as well, assuming you have some matching_key that is the product identifier then something like the following will work.

The key is the IN Data Set Option.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

data new_not_in_old;

merge new (in=newFile)

          old (in=oldFile);

by matching_key;

if newFile and not oldFile;

run;

adamsfam1
Calcite | Level 5

Thank you so much!  This answer really helped me!

ballardw
Super User

Depending on sort order of the two. It helps if both datasets are sorted in the same order. A lot.

You should define items. Is it records or variables, or both?

Proc Compare Base=OldData Compare=NewData listcompobs ;run;
will give a list of RECORD numbers in the NewData that don't exist in the Olddataset.

Proc Compare Base=OldData Compare=NewData listcompvar ;run;

List variables in the NewData not in OldData

Proc Compare Base=OldData Compare=NewData listcomp ;run;

Does what appears in both.

adamsfam1
Calcite | Level 5

Thank you so much!  This answser really helped me!

Ksharp
Super User

proc sql;

select item from new

except

select item from old ;

quit;

adamsfam1
Calcite | Level 5

Thank you so much!  This answer really helped me!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 954 views
  • 6 likes
  • 4 in conversation