BookmarkSubscribeRSS Feed
NairobiTester
Calcite | Level 5

How can I do logistic Regression in SAS Studio (SAS OnDemand for Academics) using categorical variables that have been assigned character values such as yes/no; nothing/low/medium/high; linear or non-linear; success/failed; bachelors/masters/Ph.D. and so on? Kindly help. It has really given me a headache since I'm new to SAS. See below I've attached a file holding the data set that I have to use to do logistic regression.

4 REPLIES 4
Reeza
Super User

Here's a tutorial for you that you can follow along with - full data is available.

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_logistic_examples02.htm\

 

In SAS, you can leave them as is and include them in both the CLASS and MODEL statement and specify your parameterization method. 

That's all that's needed.

 

Base example assuming you have a data set called SAMPLE, categorical variables called Status and YesNo, an outcome called Outcome and continuous variables such as Age and BP.

proc logistic data=sample;
class Status YesNo / PARAM=REF;
model outcome = Age Status YesNo BP;
run;

@NairobiTester wrote:

How can I do logistic Regression in SAS Studio (SAS OnDemand for Academics) using categorical variables that have been assigned character values such as yes/no; nothing/low/medium/high; linear or non-linear; success/failed; bachelors/masters/Ph.D. and so on? Kindly help. It has really given me a headache since I'm new to SAS. See below I've attached a file holding the data set that I have to use to do logistic regression.


 

NairobiTester
Calcite | Level 5

Hi Reeza,

I'm running the following code but I'm getting an error.

 

Error.

 ERROR: Variable NUMBER_OF_SALES_SUPPORT_MATERIAL not found.
 ERROR: Variable WORKED_IN_TOP_COMPANIES not found.
 NOTE: The SAS System stopped processing this step because of errors.
 78         proc logistic data = research.fintech1;
 79            class  number_of_sales_support_material
 80          worked_in_top_companies;
 81            model dependent_company_status= number_of_sales_support_material
 82          worked_in_top_companies number_of_sales_support_material*worked_in_top_companies skills_score
 82       ! percent_skill_entrepreneurship
 83          / expb;
 84         run;
 85         
 86         %web_open_table(RESEARCH.fintech1);
 87         
 88         
 89         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 99         

 

Kindly help with this. I have already created a library in SAS Studio called RESEARCH and linked it to the fintech1 data set. The data set has the variables I have used in my program as columns. I don't know where I go wrong. Is there something that I'm not doing right?

 

Program

%web_open_table(RESEARCH.fintech1);

proc logistic data = research.fintech1;
   class  number_of_sales_support_material
 worked_in_top_companies;
   model dependent_company_status= number_of_sales_support_material
 worked_in_top_companies number_of_sales_support_material*worked_in_top_companies skills_score percent_skill_entrepreneurship
 / expb;
run;

%web_open_table(RESEARCH.fintech1);

 

PaigeMiller
Diamond | Level 26

@NairobiTester wrote:

Hi Reeza,

I'm running the following code but I'm getting an error.

 

Error.

 ERROR: Variable NUMBER_OF_SALES_SUPPORT_MATERIAL not found.
 ERROR: Variable WORKED_IN_TOP_COMPANIES not found.
 NOTE: The SAS System stopped processing this step because of errors.
 

 

Kindly help with this. I have already created a library in SAS Studio called RESEARCH and linked it to the fintech1 data set. The data set has the variables I have used in my program as columns. I don't know where I go wrong. Is there something that I'm not doing right?

When SAS says the variable is not found, it is because the variable is not in the data set research.fintech1. So, when you imply that the variables are in the data set, SAS disagrees, and in these situations, I believe SAS. Perhaps you have spelled the names wrong.

 

Please check the PROC CONTENTS for data set research.fintech1 and see for yourself.

--
Paige Miller
PaigeMiller
Diamond | Level 26

As I don't download attachments, I can't see your data. The preferred method to make (a portion of) your data is via these instructions.

 

Logistic regression with categorical variables requires you to list the categorical variable in a CLASS statement. Example:

 

proc logistic data=have;
    class categorical_variable1 categorical_variable2;
    model y=categorical_variable1 categorical_variable2;
run;
--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3116 views
  • 0 likes
  • 3 in conversation