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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.