DATA Step, Macro, Functions and more

Trying to join two data sets with a data step

Reply
N/A
Posts: 0

Trying to join two data sets with a data step

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
Super Contributor
Posts: 359

Re: Trying to join two data sets with a data step

Posted in reply to deleted_user
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.
N/A
Posts: 0

Re: Trying to join two data sets with a data step

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.
Super Contributor
Posts: 359

Re: Trying to join two data sets with a data step

Posted in reply to deleted_user
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
N/A
Posts: 0

Re: Trying to join two data sets with a data step

Flip,
Thank you that clears it up. It makes so much sense now.

Thank you for your time and help

Jerry
Ask a Question
Discussion stats
  • 4 replies
  • 164 views
  • 1 like
  • 2 in conversation