DATA Step, Macro, Functions and more

Add variable cust from data set 2 to data set 1

Reply
New Contributor
Posts: 3

Add variable cust from data set 2 to data set 1

Hi,

 

i have two data sets and i want final data set to have all cust_1 corresponding values to cust;

please see below inputs and outputs.

 

data 1;        

cust

123

456

789

012

 

 

data2;

cust_1

345

678

901

 

desired output ;

cust cust_1

123  345

456  345

789  345

012  345

123  678

456  678

789  678

012  678

123  901

456  901

789  901

012  901

 

thanks

 

 

Super User
Posts: 5,081

Re: Add variable cust from data set 2 to data set 1

For many-to-many, all combinations matching, SQL is simplest:

 

proc sql;

create table want as select * from data1, data2;

quit;

New Contributor
Posts: 3

Re: Add variable cust from data set 2 to data set 1

Hi thanks for prompt response.
But I have already tried the code you mentioned and does not gives me the
require output. Can you please check desired output and advise?

Thanks
Rob
##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 5,081

Re: Add variable cust from data set 2 to data set 1

I won't be able to actually run any tests until Monday.  But you can help by explaining what you mean when you say it doesn't give you the desired output.

 

Did you get an error message?

 

DId you get output that was different than what you wanted?

 

In either case, show any helpful information (starting with the log from your test).

Frequent Contributor
Posts: 103

Re: Add variable cust from data set 2 to data set 1

Hi,

 

@Astounding's code is correct.

 

data one;        
input cust $;
cards;
123
456
789
012
;
run;
 
 
data two;
input cust_1 $;
cards;
345
678
901
;
run;
 
proc sql;
   create table want as select * from one, two;
quit;
________________________

- That still only counts as one -

Ask a Question
Discussion stats
  • 4 replies
  • 67 views
  • 0 likes
  • 3 in conversation