BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
twix17
Obsidian | Level 7

Hello Community,

I am trying to give a rank to a product in the order they appear on my table. Here is my data Have 

customer_Idorder_idorder
a168TV
a169TV
a170TV
a171Radio
a172Radio
a173Radio
b174TV
b175TV
b176TV
b177TV
b178TV
b179TV
c180TV
c181TV
c182Radio
c183Radio
c184Radio

 

And below is my data Want.

Idorder_idorderRank
a168TV1
a169TV1
a170TV1
a171Radio2
a172Radio2
a173Radio2
b174TV1
b175TV1
b176TV1
b177TV1
b178TV1
b179TV1
c180TV1
c181TV1
c182Radio2
c183Radio2
c184Radio2

 

Thanks for helping.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input customer_Id $ order_id order $;
datalines;
a 168 TV
a 169 TV
a 170 TV
a 171 Radio
a 172 Radio
a 173 Radio
b 174 TV
b 175 TV
b 176 TV
b 177 TV
b 178 TV
b 179 TV
c 180 TV
c 181 TV
c 182 Radio
c 183 Radio
c 184 Radio
;

data want;
   set have;
   by customer_Id order notsorted;
   if first.customer_Id then rank = 0;
   if first.order then rank + 1;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input customer_Id $ order_id order $;
datalines;
a 168 TV
a 169 TV
a 170 TV
a 171 Radio
a 172 Radio
a 173 Radio
b 174 TV
b 175 TV
b 176 TV
b 177 TV
b 178 TV
b 179 TV
c 180 TV
c 181 TV
c 182 Radio
c 183 Radio
c 184 Radio
;

data want;
   set have;
   by customer_Id order notsorted;
   if first.customer_Id then rank = 0;
   if first.order then rank + 1;
run;
twix17
Obsidian | Level 7

Thank you this works perfectly.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 933 views
  • 1 like
  • 2 in conversation