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?
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;
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;
Thank you Tom. I was way over complicating the issue.
No, the groups have various numbers of accounts.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.