BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

Hi,

I have the following two tables and I want to get the rows from both tables where the key does not match using PROC SQL.

Data Company;

input Deptid name$10. ;

datalines;

101 ram

102 dam

103 fff

104 ggg

105 sss

106 aaa

;

run;

proc print data=company;run;

Data Dept;

  input Deptid noe;

  datalines;

  101 100

  103 30

  201 200

  301 20

  ;

run;

Desired output:

Deptid Name Noe

102 dam

104 ggg

105 sss

106 aaa

201              200

301               20

Please share your thoughts.

1 REPLY 1
Patrick
Opal | Level 21

Have a read of the following link. I consider this quite helpful information.

SAS(R) 9.2 SQL Procedure User's Guide

As a variation of "Producing Rows from the First Query or the Second Query" below code should do:

proc sql;
  create table want as

    select * from Company
      where Deptid not in (select Deptid from Dept)
    outer union corr
    select * from Dept
      where Deptid not in (select Deptid from Company)
  ;
quit;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 865 views
  • 1 like
  • 2 in conversation