Subsetting IF and Nth highest salary using Proc SQL

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;

 

Advertisements

Tagged: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: