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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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