2 SAS Tips: Subsetting IF and Nth highest count using Proc SQL

Posted: January 24, 2012 in SAS Tips & Tricks

1. Subsetting IF statement without any condition:
(Visitor Contribution:)
data one;
input age;
if age;
cards;
23
12
.
45
0
54
-21
43
;
run;

Output Dataset created:
age
23
12
45
54
-21
43

Conclusion: So, use above IF statement only for FLAG variables which contains values as 0 or 1 (or) . or 1
to have lesser confusion. I mean use it only when you are sure about the data!

2. Extract Nth highest salary from SALARY table using Proc SQL:
data salary;
input sal;
cards;
23
12
.
45
0
54
-21
43
;
run;

%let N=3;
proc sql;
select a.sal from salary a where &N= (select count(distinct sal) from salary b where a.sal<=b.sal);
quit;

Happy Learning 🙂

Comments
  1. Vikas says:

    very intersting

  2. Mukul says:

    Hi can you please explain what is happening in the code. Is a cross join happening. Please Explain if possible

Leave a comment