SAS Programming

DATA Step, Macro, Functions and more
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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 5507 views
  • 7 likes
  • 3 in conversation