BookmarkSubscribeRSS Feed
sss
Fluorite | Level 6 sss
Fluorite | Level 6
data temp;
input csid asset cost;
datalines;
1001 123 10
1001 254 30
1001 554 15
2001 235 05
2001 100 10
2001 145 15
2001 470 60
5101 235 02
5101 478 10
2000 123 10
2000 456 10
;
run;

HI

I want to select top two rows form each CSID variable by whose cost is higher
3 REPLIES 3
Oleg_L
Obsidian | Level 7
Hello.
Try this code.
[pre]
proc sort data=temp; by csid descending cost; run;
data temp2; retain n 0; set temp; by csid descending cost;
if first.csid then n=1; else n=n+1;
if n le 2;
run;

[/pre]
sss
Fluorite | Level 6 sss
Fluorite | Level 6
Thnx you a lot it works
Ksharp
Super User
If you do not want ties.


[pre]
data temp;
input csid asset cost;
datalines;
1001 123 10
1001 254 30
1001 554 15
2001 235 05
2001 100 10
2001 145 15
2001 470 60
5101 235 02
5101 478 10
2000 123 10
2000 456 10
;
run;
ods output extremevalues=nextrval(keep=csid high) ;
proc univariate data=temp nextrval=2;
class csid;
var cost;
run;

proc print;run;
[/pre]



Ksharp Message was edited by: Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2348 views
  • 0 likes
  • 3 in conversation