BookmarkSubscribeRSS Feed
septemberbulb
Obsidian | Level 7

Hello, I am trying to apply the following conditions:

but for the fifth and sixth conditions, for the situation does not meet any above requirements, I am not quite sure how to deal with that : 

I am trying to add a type for each unique client ID

  • if a client ID has records with segment in ('D', 'M', 'P2', 'P1') and not equal to ‘T’-> Type A
  • if a client ID has records with segment equal to ‘T’ and none in ('D', 'M', 'P1', 'P2') -> Type B
  • if a client ID has records with segment equal to 'I'  and none in ('D', 'M', 'P1', 'P2',’T’) -> Type C
  • if a client ID has no records with segment in ('D', 'M', 'P2', 'P1',’T’) -> Other
  • if a client ID does not meet any of above requirements but revenue1 >0 and revenue2>0 ->Type A
  • if a client ID does not meet any of above requirements but has  revenue1 <=0 and revenue2<=0 -> Type B
Customer_IDAccount_IDRecord_DateSegmentRevenue1Revenue2
A100117-Dec-18N00
A100117-Apr-19N00
A100117-Aug-19N00
A1001  00
A100217-Apr-19N05000
A100217-Feb-19M100004000
A10031-Jan-20P240103000
A10031-Feb-20N46004444
A10032-Feb-20P243303509
A10033-Feb-20N50005890
A20044-Apr-21I00
A200418-Oct-21I00
A200517-Aug-20 00
A200617-Aug-20P21345667
A200619-Oct-20N13561389
A200717-Dec-18SS00
A200819-Aug-19T00
A200821-Oct-19I00
A200821-Dec-20N00
A200819-Apr-21P2999400
B100915-Apr-19N89977689
B100919-Aug-19N758456
B100921-Oct-19N-869-467
B100916-Dec-19SS00
B100919-Oct-20N00
B100921-Dec-20N00
B101018-Apr-18I00
B101015-Oct-18I00
B101017-Jun-19N00
B201116-Oct-17I-97-97
B201118-Dec-17N0-98
B201119-Feb-18Q00
B201121-Apr-20Q00
B201125-Jun-20Q00
B201116-Oct-17Q00
B201118-Apr-18Q00
B201115-Apr-19T00
B201125-Jun-20T00
B201117-Aug-20T00
B201221-Jun-21T00
B201216-Aug-21D47-900
B201218-Oct-21T-90-89
B201220-Dec-21T0-78
B201219-Oct-20N13567890
B201317-Dec-18SS-15050
B201318-Feb-19T034909
B201416-Dec-19T-156786
B201417-Feb-20T-123
B201425-Jun-20I-1456-456
B201417-Aug-20I-2456-4738

Thank you

5 REPLIES 5
Reeza
Super User

Is a client identified by a combination of CustomerID and AccountID?

 

I'm guessing that it's actually an order of operation issues 

CASE goes in order of conditions, you may need to move your fourth condition to the last condition or it will catch the last two condition. 

 

This order:

  • if a client ID has records with segment in ('D', 'M', 'P2', 'P1') and not equal to ‘T’-> Type A
  • if a client ID has records with segment equal to ‘T’ and none in ('D', 'M', 'P1', 'P2') -> Type B
  • if a client ID has records with segment equal to 'I'  and none in ('D', 'M', 'P1', 'P2',’T’) -> Type C
  • if a client ID does not meet any of above requirements but revenue1 >0 and revenue2>0 ->Type A
  • if a client ID does not meet any of above requirements but has  revenue1 <=0 and revenue2<=0 -> Type B
  • if a client ID has no records with segment in ('D', 'M', 'P2', 'P1',’T’) -> Other

If something like that doesn't work, please post what the Type is for each of your codes shown and include the code you have so far.

 

Spoiler

@septemberbulb wrote:

Hello, I am trying to apply the following conditions:

but for the fifth and sixth conditions, for the situation does not meet any above requirements, I am not quite sure how to deal with that : 

I am trying to add a type for each unique client ID

  • if a client ID has records with segment in ('D', 'M', 'P2', 'P1') and not equal to ‘T’-> Type A
  • if a client ID has records with segment equal to ‘T’ and none in ('D', 'M', 'P1', 'P2') -> Type B
  • if a client ID has records with segment equal to 'I'  and none in ('D', 'M', 'P1', 'P2',’T’) -> Type C
  • if a client ID has no records with segment in ('D', 'M', 'P2', 'P1',’T’) -> Other
  • if a client ID does not meet any of above requirements but revenue1 >0 and revenue2>0 ->Type A
  • if a client ID does not meet any of above requirements but has  revenue1 <=0 and revenue2<=0 -> Type B
Customer_ID Account_ID Record_Date Segment Revenue1 Revenue2
A1 001 17-Dec-18 N 0 0
A1 001 17-Apr-19 N 0 0
A1 001 17-Aug-19 N 0 0
A1 001     0 0
A1 002 17-Apr-19 N 0 5000
A1 002 17-Feb-19 M 10000 4000
A1 003 1-Jan-20 P2 4010 3000
A1 003 1-Feb-20 N 4600 4444
A1 003 2-Feb-20 P2 4330 3509
A1 003 3-Feb-20 N 5000 5890
A2 004 4-Apr-21 I 0 0
A2 004 18-Oct-21 I 0 0
A2 005 17-Aug-20   0 0
A2 006 17-Aug-20 P2 1345 667
A2 006 19-Oct-20 N 1356 1389
A2 007 17-Dec-18 SS 0 0
A2 008 19-Aug-19 T 0 0
A2 008 21-Oct-19 I 0 0
A2 008 21-Dec-20 N 0 0
A2 008 19-Apr-21 P2 999 400
B1 009 15-Apr-19 N 8997 7689
B1 009 19-Aug-19 N 758 456
B1 009 21-Oct-19 N -869 -467
B1 009 16-Dec-19 SS 0 0
B1 009 19-Oct-20 N 0 0
B1 009 21-Dec-20 N 0 0
B1 010 18-Apr-18 I 0 0
B1 010 15-Oct-18 I 0 0
B1 010 17-Jun-19 N 0 0
B2 011 16-Oct-17 I -97 -97
B2 011 18-Dec-17 N 0 -98
B2 011 19-Feb-18 Q 0 0
B2 011 21-Apr-20 Q 0 0
B2 011 25-Jun-20 Q 0 0
B2 011 16-Oct-17 Q 0 0
B2 011 18-Apr-18 Q 0 0
B2 011 15-Apr-19 T 0 0
B2 011 25-Jun-20 T 0 0
B2 011 17-Aug-20 T 0 0
B2 012 21-Jun-21 T 0 0
B2 012 16-Aug-21 D 47 -900
B2 012 18-Oct-21 T -90 -89
B2 012 20-Dec-21 T 0 -78
B2 012 19-Oct-20 N 13567 890
B2 013 17-Dec-18 SS -150 50
B2 013 18-Feb-19 T 0 34909
B2 014 16-Dec-19 T -1 56786
B2 014 17-Feb-20 T -1 23
B2 014 25-Jun-20 I -1456 -456
B2 014 17-Aug-20 I -2456 -4738

Thank you


septemberbulb
Obsidian | Level 7

For example, for client ID A, it has multiple records as long as any records meet the condition, based on the logic, the result will mark the client ID A is Type A. But when I use case when,  the result only helps me generate a type after each row. it is not a aggerated view for each Client. Group by Client.

septemberbulb
Obsidian | Level 7

Sorry Let me repost this for a better view. 

Reeza
Super User

Show your code. 

 

Your code is very likely wrong but without seeing it, can't say how. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 5 replies
  • 445 views
  • 0 likes
  • 3 in conversation