BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have data set A & B and they both have an ID column to join on.
I would like to do a inner join and i'm not sure how to do that. I am unable to use a proc sql step because i'm
trying to learn more about data steps and how they are used.

Table A
ID Name
1 Bob
2 Fred
3 Dave

Table B
ID Age
1 30
3 40

I would like my data set to be
ID Name Age
1 Bob 30
3 Dave 40

With this merge it brings back everything from both. Is there an option i'm missing or can't I do that with a merge?
data C ;
merge A B;
by ID ;
run ;


Thank you for an advice
4 REPLIES 4
Flip
Fluorite | Level 6
data C ;
merge A(in = aval) B(in = bval);
by ID ;
if aval and bval;
run ;

The IN opperator tells you if the value is in that table.
deleted_user
Not applicable
Flip,
Based on my example what would aval and bval be?
Are these seperate columns containing my ID for each?

Thank you for the reply.
Flip
Fluorite | Level 6
They are temporary variables set by the (in= varname) option. They indicate which table the value comes from.
http://www.cpc.unc.edu/services/computer/presentations/sasclass99/merge.html
deleted_user
Not applicable
Flip,
Thank you that clears it up. It makes so much sense now.

Thank you for your time and help

Jerry

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 4 replies
  • 1166 views
  • 1 like
  • 2 in conversation