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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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