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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 375 views
  • 1 like
  • 2 in conversation