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

Hi, 

 

I have a dataset like below:

 

id   date   type

1    SEP    A

1    SEP    B

1    SEP    C

2    SEP   B

3   SEP     C

4   SEP    B

4   SEP    C

 

I want like below:  group by id,date, if this id in specific time, in all the type he has, if he has type A then his new type will be A and ignore other type.

so the important type should be A>B>C. 

 

id   date   type_new

1    SEP    A

 

2    SEP   B

3   SEP     C

4   SEP    B

 

how can I solve this? Thank you! 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

I would keep a look up table like, and it;s easy to update look up table when needed

 

Type  rank

a          1

b         2

c        3 

 

and look up using join, merge, hash,format etc

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

if the type is actually A,B,C etc ranked i.e sorted by hierarchy as your sample is 

all you need is

 

data want;

set have;

by id date type;

if first.id;

run;

jojozheng
Quartz | Level 8
if it is not in that order, it shuffles like
1 sep b
1 sep c
1 sep a

what should I do?
novinosrin
Tourmaline | Level 20

I would keep a look up table like, and it;s easy to update look up table when needed

 

Type  rank

a          1

b         2

c        3 

 

and look up using join, merge, hash,format etc

jojozheng
Quartz | Level 8
thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 2248 views
  • 1 like
  • 2 in conversation