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

Hello Guys,

 

Could you please help to get the below problem solved:

 

STATE  CITY   VALUE  COUNT

A            1          F           1

A             2         F           1

A            3          G           2

B            4         G            1

B            5          H           2

B            6          H           2

C           7          J            1

C           8          K            2

C           9         F             3

 

 

I need to rank the values , as given in count variable.

 

Thanks!

Parveen

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Yeah, without seeing your code I can't comment. 

Use @Ksharp solution, because your data isn't sorted in a standard manner, in your last group the J/K/F grouping would be incorrect. 

 

The suggested (incorrect) code based on the link should have been:

 

data want;
set have;
by state value;
retain your_sol;

if first.state then your_sol=0;
if first.value then your_sol+1;

run;

View solution in original post

5 REPLIES 5
Reeza
Super User

http://www.ats.ucla.edu/stat/sas/faq/enumerate.htm

 

Your BY groups appear to be STATE & VALUE

Lohia
Calcite | Level 5

Hi Reeza,

 

Its showing as below:

STATE  CITY   VALUE  COUNT   Your_sol

A            1          F           1            1

A             2         F           1            2

A            3          G           2           1

B            4         G            1            1

B            5          H           2             1

B            6          H           2            2

C           7          J            1            1

C           8          K            2            1

C           9         F             3           1

 

Thanks!

Parveen

Reeza
Super User

Yeah, without seeing your code I can't comment. 

Use @Ksharp solution, because your data isn't sorted in a standard manner, in your last group the J/K/F grouping would be incorrect. 

 

The suggested (incorrect) code based on the link should have been:

 

data want;
set have;
by state value;
retain your_sol;

if first.state then your_sol=0;
if first.value then your_sol+1;

run;
Ksharp
Super User

OK. Assumiing your data has been sorted like you showed.

 

data have;
input STATE $ CITY   VALUE  $;
cards;
A            1          F        
A             2         F       
A            3          G        
B            4         G      
B            5          H    
B            6          H     
C           7          J        
C           8          K    
C           9         F 
;
run;
data want;
 set have;
 by  STATE  VALUE notsorted;
 if first.STATE then count=0;
 count+first.VALUE;
run;
Lohia
Calcite | Level 5

Thanks a lot Reeza and Ksharp . Really helpful guys 🙂 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 2490 views
  • 0 likes
  • 3 in conversation