Hi All, can you please explain crisply how the below query is working,
i wanted to know how where confition checking the each observtion of table b with every observation of table a.
/* Quesry is used to find the ranks*/
data a;
input id sal;
cards;
1 100
2 200
3 300
9 78
10 890
11 890
;
proc sql;
select a.*,(select count(distinct sal) from a where b.sal le a.sal) as r from a b;
quit;
Quite simply a and b are the same table which you are joining with itself - b is just an alias for a which is set up by the "from a b" portion of the query.
Conceptually, SAS is running a subquery for every observation of table a. Since that subquery also involves table a, you must give the table an alias name (b) so as to allow an expression like "b.sal le a.sal". I think the query should be written as
proc sql;
select
b.*,
( select
count(distinct id)
from a
where b.sal le a.sal ) as r
from a as b;
quit;
@shivamarrora0 wrote:
Hi, I wanted to know the reason why b.sal le a.sal
comparing 1 observation of B table to every observation of A table .. ?
This would one approach to "how many salary values are the same or more than the person with the givend ID, including that person".
Is a "what" answer. Why is up to your rules.
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.
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.