BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pcfriendly
Calcite | Level 5

Hi Bruno,

My options to choose under the Data area in the Rank icon are as follows;

  • Job_Role sort order - which I've set to Descending
  • Columns to Rank - Start_Date
  • Rank By - Job_Role
  • Sort by Variables checkbox - not sure if I should leave it checked?

My options to choose under the Options area in the Rank icon are as follows;

  • Ranking method - Smallest to Largest Radio Button
  • If values tie, use; - Default is Median, other options are 'High Rank', 'Low Rank'
  • There's also a checkbox for 'Reverse Ranking from largest to smallest' doesn't this negate the Ranking Method already set to 'Smallest to Largest?

The date field I'm using is a Date Time value & I'm getting results like 403.5 in my ranking results??

luo
Calcite | Level 5 luo
Calcite | Level 5

Use subquery. such as below

 

proc sql;

select c1.make,
	c1.model,
	c1.invoice,
	(
		select count(*)
		from sashelp.cars c2
		where c2.make=c1.make
		and c2.invoice>=c1.invoice
	) as rankings
from sashelp.cars c1
order by c1.make,c1.invoice DESC
;

run;
pcfriendly
Calcite | Level 5

Thanks to all, especially, Reeza & Bruno.

I eventually figured out to do the Rank using only the 2 Fields & got the Rank Number & then ran a query builder to select where the Rank Number = 1 as you said Bruno.

This will come in very handy, Cheers

Peter

HRI
Calcite | Level 5 HRI
Calcite | Level 5

you can use proc rank to rank your data first, then using the rank to find first, second, .... or last one.

Eurisko
Calcite | Level 5

It's all well and good that you can rank using the menu system, however how would this translate to code?

SamuelD
Fluorite | Level 6

Hi there,

 

When i hav a challenge working out the code i use the GUI and then click on the code tab once executed to see what SAS EG does.

 

The ranking code would look like this:

PROC SORT
	DATA=inputdata  
	OUT=sorted_data_set
	;
	BY {customer number};
RUN;
PROC RANK DATA = sorted_data_set
	DESCENDING /* use decending if using dates so the most current record is a 1 */
	TIES=LOW
	OUT=WORK.RankedData;
	BY {customer number};
	VAR {date};
RANKS ranking_number;
RUN;
QUIT;

 

You may need to do query after this to filter the output so you are selecting records that have a rank of 1.

 

 

Hope this helps.

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 20 replies
  • 47004 views
  • 3 likes
  • 8 in conversation