BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
deega
Quartz | Level 8

I wrote the following code :

 

proc sql;
create table new as
SELECT *
FROM A,B
where A.AID= B.BID ;

 

My output is almost as desired except the ones with missing values.
There are few observations in A where AID is missing and in final output
instead of getting the set of observations as it is, I am getting it repeated
n number of times. Could anybody please tell me the reason for the same.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Instead of entering zeros by hand, you could do

 

proc sql;
create table base_3 as
SELECT *
FROM A
LEFT JOIN B
ON coalesce(A.AID,0)= B.BID ;
quit;

(untested)

PG

View solution in original post

4 REPLIES 4
deega
Quartz | Level 8
I have got one solution, I manually entered 0 wherever the key value was missing and then did left join as follows
proc sql;
create table base_3 as
SELECT *
FROM A
LEFT JOIN B
ON A.AID= B.BID ;
quit;

Its working... However, if there is a better way.. advise is welcome !
PGStats
Opal | Level 21

Instead of entering zeros by hand, you could do

 

proc sql;
create table base_3 as
SELECT *
FROM A
LEFT JOIN B
ON coalesce(A.AID,0)= B.BID ;
quit;

(untested)

PG
deega
Quartz | Level 8
Tested, its working ! Thanks !
Reeza
Super User

It's your join type that causes the issue, just doing a left join should help, though they'd be blank, not 0 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1414 views
  • 1 like
  • 3 in conversation