BookmarkSubscribeRSS Feed
Cecillia_Mao
Obsidian | Level 7

Hi everyone,

 

I'm doing a logistic regression. However, I need to convert about 20 independent characteristic variables to numeric ones in order to check assumptions. I have seen something like an option(probably in a proc step) to change yes/no to 0/1 in just one step (Not if then, not proc format, not array), but I totally forgot where it came from. I tried my best to search similar stuff( "categorical variable to 1 2 3 in one step",etc), but I haven't found anything like an option that can do the job. I'm sorry that I can't provide more information, any hints would be APPRECIATED!

9 REPLIES 9
Cecillia_Mao
Obsidian | Level 7

Thanks so much, Chris! It's not exactly what I'm looking for, but it's much better than if-then and proc format in some cases!  Thanks for sharing!

PaigeMiller
Diamond | Level 26

@Cecillia_Mao wrote:

 

I'm doing a logistic regression. However, I need to convert characteristic variables to numeric ones in order to check assumptions. 


What assumptions? There are not usually any assumptions on character variables, and so no checking is required. So, no conversion to numeric is required either.

 

Logistic regression will run just fine with a character variable as the response.

 

Logistic regression will run just fine with character x-variables if you indicate the variables are character in the CLASS statement.


Again, no conversion from character to numeric is needed for logistic regression. Do the easy thing in this case, use your data as is.

--
Paige Miller
Cecillia_Mao
Obsidian | Level 7

Hi Paige, 

Thanks for the reply! I'm checking the  MULTICOLLINEARITY assumption, and I'm using the "Correlation matrix"  criteria, which means I need to use “proc corr ” that needs numerical variables.  BTW, this is the material I'm referring to
https://www.lexjansen.com/wuss/2018/130_Final_Paper_PDF.pdf . 

 

PaigeMiller
Diamond | Level 26

Perhaps something needs to be clarified in your original post.

 

Are these character variables that you need to convert to numeric x-variables or y-variables? How many are there?

 

--
Paige Miller
Cecillia_Mao
Obsidian | Level 7
Thanks for pointing that out, it had been a little bit confusing. I revised the original post a little bit. They are about 20 independent character variables that need to be converted to numeric ones.
PaigeMiller
Diamond | Level 26

@Cecillia_Mao wrote:
Thanks for pointing that out, it had been a little bit confusing. I revised the original post a little bit. They are about 20 independent character variables that need to be converted to numeric ones.

So you really ought to create dummy variables, and if there are more than two levels of a specific variable, this is more complicated than the suggestion from @ChrisNZ . Here is a long thread on many different ways to create dummy variables.

 

Also, checking multicollinearity is not checking "assumptions", so that threw me off. An assumption in modeling would be something like does a variable have the proper distribution. Multicollinearity is certain a concern, but it isn't what I think would be called an "assumption".

--
Paige Miller
Tom
Super User Tom
Super User

Do you really need to create dummy variables?  Can't you just use a CLASS statement in your analysis step?

 

Perhaps you are thinking of the GLMMOD procedure?  That should be able to generate dummy variables from your CLASS variables.

Cecillia_Mao
Obsidian | Level 7

Hi Tom,

Thanks for the reply! I made the case a little bit confused in the original post. If only considering running the model itself, the class statement would be enough. However, I just want to change character variables to 0,1,2,3... for assumption check, which sometimes requires the data in numeric format. Thanks again!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 9 replies
  • 1346 views
  • 0 likes
  • 4 in conversation