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

I'm trying to merge two different datasets, keeping some variables of the second dataset.

 

I used the following code:

 

proc sort data = MO;
by n;
run;
proc sort data = TE;
by n;
run;

Data MOTE; 
Merge   MO (in=A) TE (in=B keep = n UltMes MesSEMReg);
		by n;
		If A;
		run;

 

In the merged data set the variables UltMes MesSEMReg exist but they are empty.

 

Can you help me solving this problem?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ramgouveia
Obsidian | Level 7

Sorry @ballardw and @Astounding 

 

Thank you for your help.

 

I have misspecified the name of the second dataset. Correcting it, solves the error.

View solution in original post

5 REPLIES 5
ballardw
Super User

Since you are only keeping records that have matching values of N in the data set MO the most likely cause of "missing" values for those variables is that your data set TE does not have values when the N matches.

 

You can test this with:

Proc freq data=TE;
   tables n * (UltMes MesSEMReg) /list missing;
run;

and look at the values of N in the MO data set and see what you have for UltMes and Messemreg for those in TE.

 

Next most likely

ramgouveia
Obsidian | Level 7

@ballardw 

 

Both variables UltMes and  MesSEMReg of dataset TE have registers in all of the fields.

 

The problem is not that one you helpfully suggested.

ballardw
Super User

@ramgouveia wrote:

@ballardw 

 

Both variables UltMes and  MesSEMReg of dataset TE have registers in all of the fields.

 

The problem is not that one you helpfully suggested.


Are you sure that you have any matches of the BY variable? The code you used would have no contribution from TE if there are no matching values of N.

Did you 1) actually run the Proc Freq code I suggested and 2) compare any of the N values from the Freq output with the MO data set?

 

Just looking at displayed values may not be sufficient. Formats can round values to appear the same and if N is character leading spaces or non-printable characters may be present that make them not equal.

Astounding
PROC Star

By any chance, do these variables:

n UltMes MesSEMReg

 already exist in the TO data set before you merge?

ramgouveia
Obsidian | Level 7

Sorry @ballardw and @Astounding 

 

Thank you for your help.

 

I have misspecified the name of the second dataset. Correcting it, solves the error.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 3412 views
  • 7 likes
  • 3 in conversation