I have categorical variable ( string variable) with 3 levels: one, two and three. I would like to recode this variable to have these levels as 1, 2 and 3. Thank you
How do you want to use the variable? Are you wanting a numeric value or are you asking for IF/Then/Else type code to reassign values of the existing variable?
I ask because a SAS Format is a typical way to change displayed values without changing data which is sometimes more flexible and quicker than actually changing values. But display order is not always as expected depending on the procedures used.
Variable will be used in certain model as predictor. Actually I run the model using the original variable and I got weird results. So I want to recode the variable either by creating new variable or just replacing it.
You might be better showing the code for the model and the results that you think are weird, describing in what way they are "weird".
I have a hard time thinking of a true categorical variable that changing the coding in a one-to-one fashion would affect the model.
Recoding your strings to 1 2 3 does not change the model. It is a waste of time in modeling.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.