« The Beginning of the End of the Internet | Main | Use Proc SQL to summarize tables into groupings »

Merge datasets with unlike variable names

Here is an example of merging datasets with Unlike variable names:

Data  DS1;
INPUT A $ B $ C $ ;
Cards ;
Small Tike Red
Med Bike Blue
Large Bike Red
;

Data DS2 ;
INPUT X $ Y $ Z $ ;
Cards ;
Small 10.99 1yr
Small 20.99 2yr
Large 50.00 1yr
;

run;

proc sql;
create table AllDS as
 select coalesce(ds1.a,ds2.x) as ax, b, c, y, z
  from ds1 full join ds2
  on ds1.a = ds2.x
  order by ax desc;
quit;

Code is also available on my Snippet Code repository.

Kudos to the guys on the SAS google group thread for coming up with this solution. 

Posted on Saturday, May 3, 2008 by Registered CommenterJared in , | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>