Hello everyone,
Can anyone suggest me a code for logistic regression
Question: Perform a logistic regression with covariates age/sex/race on the outcome of having at least 1 visit to a Primary Care Provider. (PCP = Primary Care Provider)
ID PCP SEX RACE AGE
1 8 1 1 71
2 8 1 1 65
3 8 2 1 81
4 8 1 1 75
5 8 2 1 83
6 8 2 1 79
7 8 1 1 66
8 8 2 1 71
9 8 1 1 86
10 8 2 1 70
11 8 2 1 76
12 8 1 1 75
13 8 2 1 66
14 8 2 1 91
15 8 2 1 67
Any help will be appreciated.
The first thing you need to do is to get your data in a form that suits the question. If you want to model the outcome of having at least 1 visit to a Primary Care Provider, then PCP should be a binary variable, created like below. The example code for the logistic regression can then easily be found in the Examples Section of the PROC LOGISTIC Documentation.
data have;
input ID PCP SEX RACE AGE;
datalines;
1 8 1 1 71
2 8 1 1 65
3 8 2 1 81
4 8 1 1 75
5 8 2 1 83
6 8 2 1 79
7 8 1 1 66
8 8 2 1 71
9 8 1 1 86
10 8 2 1 70
11 8 2 1 76
12 8 1 1 75
13 8 2 1 66
14 8 2 1 91
15 8 2 1 67
;
data RegData;
set have;
PCP=(PCP>0);
run;
The first thing you need to do is to get your data in a form that suits the question. If you want to model the outcome of having at least 1 visit to a Primary Care Provider, then PCP should be a binary variable, created like below. The example code for the logistic regression can then easily be found in the Examples Section of the PROC LOGISTIC Documentation.
data have;
input ID PCP SEX RACE AGE;
datalines;
1 8 1 1 71
2 8 1 1 65
3 8 2 1 81
4 8 1 1 75
5 8 2 1 83
6 8 2 1 79
7 8 1 1 66
8 8 2 1 71
9 8 1 1 86
10 8 2 1 70
11 8 2 1 76
12 8 1 1 75
13 8 2 1 66
14 8 2 1 91
15 8 2 1 67
;
data RegData;
set have;
PCP=(PCP>0);
run;
Could you tell me what I am supposed to put in place of 'have'.
data RegData;
set have..........NOT CLEAR;
PCP=(PCP>0);
run;
If I am understanding your problem properly, this data doesn't seem to match the problem description, nor does the addition by @PeterClemmensen. You would be doing a logistic regression where the responses are 1 for every observation, which doesn't work in logistic regression. You would need some zeros in the Y variable to fit a logistic regression.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.