Home Merge two data files in SAS and create variables
Reply: 0

Merge two data files in SAS and create variables

user1056 Published in May 21, 2018, 3:12 am

I have two datasets to join and pull the details from the first table as two variables

Here are my two datasets


  ID          Code      last4_Code
 101        102345678      5678
 101        234142345      2345
 101        189765412      5412

The second dataset is a single row per id with two codes (code1 and code2)


  ID          code1      code2 
 101          5678       5412

I need my final dataset with `code' from first dataset as two different variables

 ID          Code1_a       Code2_a
101         102345678     189765412

I tried proc sql left join to get the multiple rows and then create two new variables

   proc sql;
    create table new as select
     a.id,b.code from
     data2 a
     left join data1 b
     on a.id=b.id
     or a.code1=b.last4_code

but this is not working as expected.

I would appreciate any help !!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316874 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO