BookmarkSubscribeRSS Feed
vjpkr
Calcite | Level 5

Hi,

When I am merging 2 datasets- A and B with 247 and 18 observations respectively as below , I am getting 248 observations in the dataset AB. Is this correct?

As much as I know, the no.of observations in the new dataset AB should be 247. Need help in solving this problem. Appreciate it.

data AB AB_dummy;

length common_variable $ 50;

merge A (in=a) B (in=b);

by common_variable;

if a then output AB;

if a and not b then output AB_dummy;

run;

2 REPLIES 2
Rwon
Obsidian | Level 7

Most likely there is 1 common variable that is in A and also in B. Thus, when you condition on 'if a then output AB' you are picking up 247 observations from dataset A and 1 observation from dataset B, yielding 248 total observations in dataset AB.

art297
Opal | Level 21

My guess is that you have a duplicate in file b. e.g.:

data a;
  input common_variable $50.;
  cards;
1
2
3
4
5
;
data b;
  input common_variable $50.;
  cards;
1
2
3
3
4
5
;
 
data AB AB_dummy;
  length common_variable $ 50;
  merge A (in=a) B (in=b);
  by common_variable;
  if a then output AB;
  if a and not b then output AB_dummy;
run;

Art, CEO, AnalystFinder.com

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 1168 views
  • 0 likes
  • 3 in conversation