I have following tables.
data Table1;
input product $ start_date :date7. end_date:date7. Price;
format start_date end_date date9.;
datalines;
p1 01Jan17 18Jan18 15
p1 19Jan18 15Jul18 30
p1 16Jul18 31Mar19 24
p2 08Jan17 31Dec17 17
p2 01Jan18 15Mar18 19
p2 26Jul18 31Mar19 18
;
Product | sd | ed | price |
p1 | 01-Jan-17 | 18-Jan-18 | 15 |
p1 | 19-Jan-18 | 15-Jul-18 | 30 |
p1 | 16-Jul-18 | 31-Mar-19 | 24 |
p2 | 08-Jan-17 | 31-Dec-17 | 17 |
p2 | 01-Jan-18 | 15-Mar-18 | 19 |
p2 | 26-Jul-18 | 31-Mar-19 | 18 |
I wanted to rank product, means p1 is rank 1 and p2 is rank 2.
Product | sd | ed | price | Rank |
p1 | 01-Jan-17 | 18-Jan-18 | 15 | 1 |
p1 | 19-Jan-18 | 15-Jul-18 | 30 | 1 |
p1 | 16-Jul-18 | 31-Mar-19 | 24 | 1 |
p2 | 08-Jan-17 | 31-Dec-17 | 17 | 2 |
p2 | 01-Jan-18 | 15-Mar-18 | 19 | 2 |
p2 | 26-Jul-18 | 31-Mar-19 | 18 | 2 |
data want;
set Table1;
by product;
if first.product then Rank+1;
run;
data want;
set Table1;
by product;
if first.product then Rank+1;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.