Reputation:
I have imported a dataset from excel and I want to run a logistic regression, but SAS does not recognized continuous variables. That is the code I used:
Proc logistic data=work.heart class famhist /param=ref ref=first
model chd = tobacco ldl typea age famhist;
run;
I get the following message in Log:
"Variable tobacco should be either numeric or specified in the CLASS statement"
while tobacco is a continuous variable. What should I do?
Upvotes: 0
Views: 2249
Reputation: 63424
SAS certainly understands continuous variables, although it doesn't have a discrete type for them the way r
does. SAS has numeric and character types (and no other simple types).
However, when importing from Excel, SAS won't necessarily make a column what you think it should. In particular, Excel doesn't have a concept of type the way SAS does; a cell has a type, more or less, but a column can have whatever you want. Very often SAS will change numerics to character on importing because otherwise it would lose some data.
As Scortchi notes in the comments, there's a good chance this is from some character data like "NA" in your excel file. You can change this in a number of ways.
You can change it after the fact, like so:
data have_fixed;
set have(rename=tobacco=tobacco_c);
tobacco=input(tobacco_c,??best12.); *or whatever a reasonable informat is;
run;
The ??
tells SAS not to be worried about the ones that don't convert neatly, just make them missing (.
). If you have any logic for handling that, implement it (ie, if you have some that you want turned to some other value, do so first).
You can also tell SAS how to import specific variables.
proc import file="c:\myfile.xlsx" out=have dbms=excel replace;
dbsopts="dbsastype=(tobacco='numeric')";
run;
Upvotes: 2