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

Can some one give me a proc sql code for the following query in sas

PROC SORT DATA=x  OUT=x;

      BY a;

RUN;

PROC SORT DATA=z  OUT=z (KEEP = a b c);

      BY a;

RUN;

   

DATA  final;

      MERGE  x(IN=A) z;

      BY a;

      IF A;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Assuming that the duplicate variable of A and in=A is an accident, see page 4 here:

http://support.sas.com/resources/papers/proceedings09/035-2009.pdf

There is some default behaviour that is not replicable between the data step/sql step such as how they treat the merge if the two data sets have the same variable.

proc sql;

create table want as

select a.*, b.*

from a

left join b

on a.var1=b.var1

order by var1;

quit;

View solution in original post

5 REPLIES 5
Reeza
Super User

Use a LEFT JOIN

rakeshvvv
Quartz | Level 8

I am not sure about the syntax for LEFT JOIN...SO POSTED here...

LinusH
Tourmaline | Level 20

Have you tried Google, or support.sas.com?

Data never sleeps
Astounding
PROC Star

This program is like making mud pies ... you might have fun experimenting with it, but you would never use it.  There is no practical use for a program that uses a BY variable and an IN= variable having the same name.

Good luck.


Reeza
Super User

Assuming that the duplicate variable of A and in=A is an accident, see page 4 here:

http://support.sas.com/resources/papers/proceedings09/035-2009.pdf

There is some default behaviour that is not replicable between the data step/sql step such as how they treat the merge if the two data sets have the same variable.

proc sql;

create table want as

select a.*, b.*

from a

left join b

on a.var1=b.var1

order by var1;

quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1236 views
  • 0 likes
  • 4 in conversation