BookmarkSubscribeRSS Feed
sasg
Calcite | Level 5

Hi,

    I have two datasets dataset a and dataset b.

    ex:dataset a

    id        value

    123      xyz

     456     wxy

  112345   abc

dataset b

id     product

123   def

456   tss

789   klm

i want to map product for each id in dataset a from dataset b

final dataset should look like this:

id             value    product

123           xyz      def

456           wxy      tss

112345      abc

I'm using left outer join on id....but not getting desired results.

how can i do this.

Thanks,

rk.

3 REPLIES 3
Reeza
Super User

A standard left join should work.

ie

proc sql;

create table want as

select a.id, a.value, b.product

from tablea a

left join tableb b

on a.id=b.id;

quit;

You can (should) post your code if something like the above isn't working for you.

sasg
Calcite | Level 5

Yes,the same code i have if i test on large dataset it is not working.

getting more records than actual records.

Regards,

rk

Tom
Super User Tom
Super User

Your right hand dataset must have duplicate records for the id variables.  If they are exact duplicates then adding the DISTINCT keyword after the SELECT keyword will reduce the number of records.

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
  • 3 replies
  • 935 views
  • 0 likes
  • 3 in conversation