BookmarkSubscribeRSS Feed
AgentA
Obsidian | Level 7

Hi guys , 
I am doing inner join using proc sql, please see the below code.

 

data am;
input name$ age;
datalines;
am 89
am 78
am 45
na 23
;
run;

data am1;
input name$ marks;
datalines;
am 789
am 9081
na 2670
pa 89
sa 90
ka 09
;
run;

proc sql;
select * from am,am1 where am.name=am1.name;
quit;

 

Question : Why age=78 is below the age=45 where as in data step age=78 is above. Request, kindly explain.

SAS Output:

name age name marks
am 89 am 789
am 45 am 789
am 78 am 789
am 89 am 9081
am 45 am 9081
am 78 am 9081
na 23 na 2670
2 REPLIES 2
Reeza
Super User

RTM. You didn't specify any order so you cannot expect any order to the data. 

Also, I didn't run your code but that output doesn't match the code you've shown either. I'm assuming it's correct but you've truncated the output for some reason. 

 

 https://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#p0hwg3z33gllron18...

If an ORDER BY clause is omitted, then a particular order to the output rows, such as the order in which the rows are encountered in the queried table, cannot be guaranteed—even if an index is present. Without an ORDER BY clause, the order of the output rows is determined by the internal processing of PROC SQL, the default collating sequence of SAS, and your operating environment.

Reeza
Super User

Also, that's not an inner join it's a Cartesian join, filtered on marching name. 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1212 views
  • 0 likes
  • 2 in conversation