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

Hi again!

 

This seems like a VERY easy fix that I can't seem to get down. As the title states, I am trying to merge based on an ID variable (PID). When I go to merge the two datasets, it creates new rows even when the PID matches in both datasets. The new dataset puts all of one dataset's variables into a new row and makes the other dataset's variables missing. 

 

My code looks like this:

 

proc sort data= sub.aptcorrelations;
by pid;
proc sort data= sub.master_dataset053019;
by pid;
data Merged;
set   sub.aptcorrelations sub.master_dataset053019;
by pid;
run;

I checked the variables and both PID variables are numeric and 8 in length. They do have different labels which may matter, but I do not think that it does. 

 

I tried changing the order of the datasets and using an inner join. What could I possibly be missing here?

 

I attached a picture for clarity. I am trying to get everything on one row and matched by PID. MergeIssue.PNG

 

Here is the merge log:

 

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='S:\Alcstudy\ComboDataEntry\Joe\Inflation\Subcategories\MasterDataset and RegressionLogProp1.egp'
5        ! ;
6          %LET _CLIENTPROJECTNAME='MasterDataset and RegressionLogProp1.egp';
7          %LET _SASPROGRAMFILE=;
8          
9          ODS _ALL_ CLOSE;
10         OPTIONS DEV=ACTIVEX;
11         GOPTIONS XPIXELS=0 YPIXELS=0;
12         FILENAME EGSR TEMP;
13         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
14             STYLE=HtmlBlue
15             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
16             NOGTITLE
17             NOGFOOTNOTE
18             GPATH=&sasworklocation
19             ENCODING=UTF8
20             options(rolap="on")
21         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
22         
23         GOPTIONS ACCESSIBLE;
24         data Merged;
25         set   sub.aptcorrelations sub.master_dataset053019;
26         by pid;
27         run;

NOTE: There were 191 observations read from the data set SUB.APTCORRELATIONS.
NOTE: There were 616 observations read from the data set SUB.MASTER_DATASET053019.
NOTE: The data set WORK.MERGED has 807 observations and 7692 variables.
NOTE: DATA statement used (Total process time):
      real time           0.66 seconds
      cpu time            0.14 seconds
     MergeIssue.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Are you trying to interleave(sorted append) or merge?

 

If match merge is really your objective, the code should be using a merge statement

data Merged;
merge   sub.aptcorrelations sub.master_dataset053019;
by pid;
run;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

You have one-to-many relationships for some of the pid values.

 

Corrected: looks like you may have no matches at all, as the obs count of the output is the sum of the obscounts of the inputs.

novinosrin
Tourmaline | Level 20

Are you trying to interleave(sorted append) or merge?

 

If match merge is really your objective, the code should be using a merge statement

data Merged;
merge   sub.aptcorrelations sub.master_dataset053019;
by pid;
run;
joebacon
Pyrite | Level 9

I am an absolute moron. Thank you. I looked in every single place except the most obvious one. Wow.

Kurt_Bremser
Super User

@novinosrin wrote:

Are you trying to interleave(sorted append) or merge?

 

If match merge is really your objective, the code should be using a merge statement

data Merged;
merge   sub.aptcorrelations sub.master_dataset053019;
by pid;
run;

Gosh. Well, it's been the end of a working day ....

novinosrin
Tourmaline | Level 20

lol Well it's 9:51 AM here and am fresh although got a sinus headache that's annoying but coffee helps . Have a great afternoon  🙂

joebacon
Pyrite | Level 9

Indeed. Brand the scarlet letter on me and let me face my public humiliation. 

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!

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