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

This seems like it would be simple, but I have had no luck making it work.

 

I have a set of numbers representing account numbers.  I need to assign each number to one of  three groups.  For simplicity, let's use numbers:

111

222

333

444

555

666

777

888

999

 

The groups will belong to ABC, DEF or GHI.  The group names are not in the dataset.  How/can I write this using 1 next CASE/WHEN statement?  If so, how?

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

Here's the code I used to create the test data, and the code that is generated by the EG query builder.

 

Tom

data Have;
	input InNum;
	cards;
111
222
333
444
555
666
777
888
999
run;

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_HAVE AS 
   SELECT t1.InNum, 
          /* OutNum */
            (CASE
               WHEN (InNum in(111,333,555))
               THEN "ABC"
               WHEN (InNum in(222, 888))
               THEN "DEF"
               ELSE "GHI"
            END) AS OutNum
      FROM WORK.HAVE t1;
QUIT;

View solution in original post

4 REPLIES 4
Reeza
Super User
Are there any rules for assigning to groups? What happens if you have a number of groups that's not divisible by 3, ie if you have 10 account numbers.
TomKari
Onyx | Level 15

Here's the code I used to create the test data, and the code that is generated by the EG query builder.

 

Tom

data Have;
	input InNum;
	cards;
111
222
333
444
555
666
777
888
999
run;

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_HAVE AS 
   SELECT t1.InNum, 
          /* OutNum */
            (CASE
               WHEN (InNum in(111,333,555))
               THEN "ABC"
               WHEN (InNum in(222, 888))
               THEN "DEF"
               ELSE "GHI"
            END) AS OutNum
      FROM WORK.HAVE t1;
QUIT;
arjessup
Fluorite | Level 6

Thank you Tom.  I was way over complicating the issue.

arjessup
Fluorite | Level 6

No, the groups have various numbers of accounts.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 15763 views
  • 0 likes
  • 3 in conversation