BookmarkSubscribeRSS Feed
Tirth8
Calcite | Level 5

 

Create a new variable for place of residence, classifying everyone as residing in Mumbai or somewhere else (i.e., group guj, delhi, etc., into a single “Other” category). 

 

I have an existing data set in which one column is named as address: in which diff states are mentioned

Now I need to group them in two only one mumbai and rest of all in other

 

What code should be written?

3 REPLIES 3
ballardw
Super User

Extract the state into a separate variable if it is not already. Then either an IF/then/else block of code can assign the value you want.

Or a custom format could display the values of the variable with the state value as desired with the existing values unchanged.

PeterClemmensen
Tourmaline | Level 20

If you have existing data, then please post a representative sample and your desired result.

 

Makes it much easier to provide a usable code answer.

tom_grant
SAS Super FREQ
if index(upcase(address),'MUMBAI)>0 then state = 'Mumbai' else state = 'Other';

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1241 views
  • 1 like
  • 4 in conversation