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);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.