Hi
I am a builidng model in SAS enterprise miner by using logistic regression. This is the first time I am using miner and taken Titanic dataset from Kaggle. I have a column Age which has 19% missing value. Also, it has a column name called travelled class. I need to assign mean in place of missing value according to the class. For example, If people travelled in the first class I then I need to assign 37. If it is the second class then it is 29 and 24 if people travelled in third class.
I tried to do in impute but it doesn't have an option to fill three values in the 'Age' column. Any suggestion about how to do this?
Regards,
Dhilip
You would need to do it in a SAS Code node. Here is example code to impute Age with its mean within each level of TravClass:
proc means data=&em_import_data mean stackodsoutput;
class TravClass; /* change this to name of class variable, here and below */
var age; /* change this to name of age variable, here and below */
ods output summary=outmean;
run;
proc print data=outmean; run;
filename flow "&EM_FILE_EMflowSCORECODE";
filename pub "&EM_FILE_EMPUBLISHSCORECODE";
data _null_;
set outmean end=last;
file flow;
if _n_=1 then do;
put "if AGE = . then do;";
put " if TravClass='" TravClass "' then ";
end;
else do;
put " else if TravClass ='" TravClass "' then ";
end;
put " IMP_AGE = " mean ";";
if last then do;
put "end;";
put "else IMP_AGE = AGE;";
end;
run;
%em_copyfile(infref=flow, outfref=pub);
You would need to do it in a SAS Code node. Here is example code to impute Age with its mean within each level of TravClass:
proc means data=&em_import_data mean stackodsoutput;
class TravClass; /* change this to name of class variable, here and below */
var age; /* change this to name of age variable, here and below */
ods output summary=outmean;
run;
proc print data=outmean; run;
filename flow "&EM_FILE_EMflowSCORECODE";
filename pub "&EM_FILE_EMPUBLISHSCORECODE";
data _null_;
set outmean end=last;
file flow;
if _n_=1 then do;
put "if AGE = . then do;";
put " if TravClass='" TravClass "' then ";
end;
else do;
put " else if TravClass ='" TravClass "' then ";
end;
put " IMP_AGE = " mean ";";
if last then do;
put "end;";
put "else IMP_AGE = AGE;";
end;
run;
%em_copyfile(infref=flow, outfref=pub);
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 16. Read more here about why you should contribute and what is in it for you!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.