BookmarkSubscribeRSS Feed
SannaSanna
Quartz | Level 8

Hello-

I have been trying to merge two large datasets but having difficulty retaining all the variables.  This has typically been my ‘go to’ method:

PROC SORT DATA=ALL OUT=SOURCE NODUPKEY DUPOUT=XX; BY REGIONID LOCATIONID USERID ;RUN

PROC SORT DATA=REFERENCETAB NODUPKEY OUT=ID ; BY REGIONID LOCATIONID USERID;RUN

DATA YFYS YFNS NFYS;

      MERGE SOURCE(in=a) ID(in=b); BY REGIONID LOCATIONID USERID;

      IF A AND B THEN OUTPUT YFYS; 

      IF A=1 AND B=0 THEN OUTPUT YFNS;

      IF A=0 AND B=1 THEN OUTPUT NFYS; RUN

I am retaining A=B and A=1 and B=0. However, I am missing some variables from my ‘Source’ dataset after the merge.  I cant understand why?

I’ve also used Pro SQL for merging, but I need to control for record counts and am a bit uneasy with this method.  Can someone give me some insight?  Thank young

5 REPLIES 5
Reeza
Super User

Is your code missing some BY's or is that just a copy/paste error?

PROC SORT DATA=ALL OUT=SOURCE NODUPKEY DUPOUT=XX; BY REGIONID LOCATIONID USERID ;RUN

PROC SORT DATA=REFERENCETAB NODUPKEY OUT=ID ; BY REGIONID LOCATIONID USERID;RUN

DATA YFYS YFNS NFYS;

      MERGE SOURCE(in=a) ID(in=b); BY REGIONID LOCATIONID USERID;

      IF A AND B THEN OUTPUT YFYS; 

      IF A=1 AND B=0 THEN OUTPUT YFNS;

      IF A=0 AND B=1 THEN OUTPUT NFYS; RUN

SannaSanna
Quartz | Level 8

Yes.  There was a 'BY'  it was a copy and paste error.  Also the variables in each dataset should be unique so there should not be any over-written data.  Thank you

Reeza
Super User

Can you provide more details, preferably a proc contents on your input datasets for the merge and the proc contents from the output that is missing variables?

I don't see anything wrong in your code at first glance.

ballardw
Super User

Actually missing the variables or some variables missing values? The NODUPKEY may not be selecting the record you want/expect.

SannaSanna
Quartz | Level 8

Thank you.  I removed nodupkey and ran separately and it seemed to have worked. 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1073 views
  • 6 likes
  • 3 in conversation